Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to run bash file from perl

by SimonClinch (Deacon)
on May 17, 2011 at 15:02 UTC ( #905291=note: print w/replies, xml ) Need Help??


in reply to How to run bash file from perl

There are plenty of ways to do this. The easiest if errors and warnings can be ruled out and the output is small is the backtick operator which is also a similar operator in bash:
my $output = `thing.sh args`;
If output is extensive, but nevertheless nothing is expected to be printed to *nix channel 2, a pipe can be opened:
my $pid = open my $ph, "thing.sh args |" or die $!; while ( <$ph> ) { # process output from thing.sh } close $ph; waitpid $pid, 0;
If errors and output need separate processing (otherwise can append 2>&1 to the command in option 2), see IPC::Run3 or IPC::Open3, the latter of which takes three filehandles for channels 0 thru 2, the 0 channel needing therefore undef() instead of a filehandle, but otherwise is similar to option 2 above. Finally, if no I/O system communication is required with the process, just pass the commandline to be executed in bash (in this case the autoinvocation with arguments" to the "system" function as a single argument.

One world, one people

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://905291]
help
Chatterbox?
[shmem]: sub wanted { push @files, $File::Find::name if $File::Find::name =~/\.mp3$/ }
[Lady_Aleena]: shmem, that is understandable! The two examples in File::Find don't make sense to me on a quick glance.
[marioroy]: LA if the find worked from Unix command line, or does it not. Likely a quoting issue inside Perl qx.
[Lady_Aleena]: marioroy, the find worked fine at the command line.
[marioroy]: LA, yeah. than there's no reason why it cannot work inside qx. But chatting is hard in PM. I cannot see the code now.
[shmem]: Lady_Aleena: sometimes a quick glance isn't enough.

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2017-04-23 20:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.