Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: execute shell script from perl

by haukex (Archbishop)
on Sep 29, 2017 at 06:44 UTC ( [id://1200359]=note: print w/replies, xml ) Need Help??


in reply to execute shell script from perl

I wrote about the topic of running external commands at length here. In this case, since you seem to want to pass something to the script's STDIN and get something from its STDOUT, IPC::Run3 is a good choice IMO; it allows you to capture STDERR too if you need to. Note that running the script with a relative path ("./shellscript.sh") is another possible point of failure, as it relies on the current working directory.

use warnings; use strict; use IPC::Run3 'run3'; my $in = " string argument passed "; my @cmd = ('/path/to/shellscript.sh'); run3 \@cmd, \$in, \my @out or die "run3 failed"; $?==0 or die "command failed, \$?=$?"; chomp(@out); print "<<$_>>\n" for @out;

Update: Changed output to array to be more in line with OP's code.

Replies are listed 'Best First'.
Re^2: execute shell script from perl
by rajaman (Sexton) on Oct 02, 2017 at 21:33 UTC
    IPC::Run3 works great. Thanks all for the suggestions.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found