Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Using system (); with Strawberry Perl

by bliako (Monsignor)
on Nov 25, 2021 at 12:29 UTC ( #11139115=note: print w/replies, xml ) Need Help??


in reply to Using system (); with Strawberry Perl

A quick hack if you have cygwin installed in your computer: run each shell command (grep, mv, etc.) through cygwin's shell, like system("c:/cygwin/bin/bash.exe -c 'rm data2.txt'"); Of course you may be able to call mv.exe, rm.exe by using their fullpath, with something like this: system("c:/cygwin/bin/rm.exe data2.txt");. I am not familiar with cygwin to know if that's possible. If the above works then you can create your own system() to prepend the fullpath to any system command.

sub mysystem { my ($cmd, $args) = @_; my $finalcmd = 'c:/cygwin/bin/'.$cmd.'.exe'.' '.$args; # or ... 'c:/cygwin/bin/bash.exe -c "'.$cmd.' '.$args.'"'; return system($finalcmd); } mysystem("ls", "-al data2.txt > abc")==0 or die "system command failed +";

Thankfully I do not have any windows computer available within the borders of my estate and so all the above are untested. Therefore it is best to avoid use of rm during testing!

EDIT: check also a more elegant rewrite of the above: https://stackoverflow.com/a/55010946 . And also for the bit below, this is an informative post: The problem of "the" default shell

BUT! the advice of other Monks is much more sound than using the hack above: rewrite everything in Perl. Actually jwkrahn++ has done the work for you! Apropos File::Grep being slow, show us the codez.

bw, bliako

Replies are listed 'Best First'.
Re^2: Using system (); with Strawberry Perl
by hadrons (Novice) on Nov 25, 2021 at 18:02 UTC
    The issues I had with File::Grep involve using fgrep. When I changed to just grep it worked with greater performance. I had thought that fgrep was faster for some reason.
Re^2: Using system (); with Strawberry Perl
by hadrons (Novice) on Nov 25, 2021 at 19:16 UTC
    And jwkrahn++ did a great job

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11139115]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2022-05-22 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (80 votes). Check out past polls.

    Notices?