http://qs1969.pair.com?node_id=258705

RollyGuy has asked for the wisdom of the Perl Monks concerning the following question:

At work here we are converting a tcl script into a perl script. One of the interesting lines of the tcl script is the following:
set f_handle [open {|./script.pl >& script.log} a] -----Some deleted code-------- if [catch {close $f_handle} ] { send_mail "Script had a problem, returned non-zero status!." } else { send_mail "Script ok." }
What this code does is open a process and run "./script.pl >& script.log" alongside of the tcl script. Then later, the "catch" function waits for the script to finish (if it hasn't) and grabs the exit value of "script.pl". Is there a way to do a similar thing in perl? Remember that the "script.pl" actually runs in parallel with the tcl script.

Replies are listed 'Best First'.
Re: TCL to Perl
by mr_mischief (Monsignor) on May 16, 2003 at 19:16 UTC
    Yes, there is.

    You can manually fork() and exec() your child script then wait() for it to end and check the $? variable for its status.

    Christopher E. Stith
    use coffee;
Re: TCL to Perl
by Aristotle (Chancellor) on May 17, 2003 at 15:13 UTC
    From perldoc -f close:
    If the file handle came from a piped open "close" will additionally return false if one of the other system calls involved fails or if the program exits with non-zero status. (If the only problem was that the program exited non-zero $! will be set to 0.)
    See the perldoc for some example code and more explanation.

    Makeshifts last the longest.