Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Re: How to run bash file from perl by anonymized user 468275
in thread How to run bash file from perl by bndgyawali

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found