in reply to How to check a executable's status while running it.

system() will set the return status in $?. Check it out. :-)
  • Comment on Re: How to check a executable's status while running it.

Replies are listed 'Best First'.
Re^2: How to check a executable's status while running it.
by ikegami (Patriarch) on Apr 18, 2005 at 19:25 UTC

    It looks like the snippet checks whether a child is still running (by checking if the pipe is still open). system doesn't run a child in parallel, so your suggestion would help. It seems to me the solution would involve fork+exec (not recommended for Windows), system 1, ... (undocumented? Windows only), Win32::Process (Windows only), IPC::Open2, IPC::Open3, IPC::Run or IPC::Run3, but not system.

Re^2: How to check a executable's status while running it.
by Nesh (Beadle) on Apr 18, 2005 at 19:20 UTC
    I came up withj this
    #Returns the status object of the sync process $oExec; $oExec = system($stepName); $ouputStream = ""; while($? eq 0){ Do While Not oExec.StdOut.AtEndOfStream ouputStream = ouputStream & oExec.StdOut.ReadAll Loop sleep 100; } Do While Not oExec.StdOut.AtEndOfStream ouputStream = ouputStream & oExec.StdOut.ReadAll Loop #WScript.StdOut.Write ouputStream return $oExec; }
    Does this look right? But system won't return the output...
      open( CMD, "$command |" ) or die "Cannot open $command: $!\n"; while ( defined( my $line = <CMD> ) ) { # Do stuff with $line which is the output from $command } close CMD;
      Or, ikegami has a list of number of good modules that do similar things.