Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: stop process based on exit status.

by Mr_Person (Hermit)
on Aug 14, 2004 at 16:22 UTC ( [id://382989]=note: print w/replies, xml ) Need Help??


in reply to stop process based on exit status.

This may be a little overblown for what you need, but it will capture both the STDOUT and the STDERR to a log file, die if the program does not exist, and display the return code.
#!/usr/bin/perl use strict; use warnings; use IPC::Run qw( start pump finish ); open(LOG, '>', 'log') or die "Unable to open log: $!"; my ($in, $out); my $h = start([ 'run_tool', '-f', 'test.tcl' ], \$in, \$out, \$out); while($h->pump) { print LOG $out; $out = ''; } $h->finish; close(LOG); print "Exit code was: " . $h->result . "\n";
You'll probably want to take a closer look at the IPC::Run docs for more details on what all it can do. It also offers fairly flexible control over interactive programs if you want to do that in the future. I tend to use it over open or system any time I need to start doing anything more than just run the program.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found