in reply to knowing if process dies.

Tye was very helpful in helping me find out how to do it. I now have actual code to get the error code ( tested, and working ) .. I first created a script that would exit out with an error. THis was simple.

print "XDB19\n"; exit( 3 );


Now I needed a program to call this one, and get it's output and error code.

open( LOG, "perl ex.pl|" ); # open the program while ( <LOG> ) { print "$_"; } # print output from prog close( LOG ); # wont work without close $errcode = ( $? / 256 ); # there is a number stored # in the $? variable, and # it happens to be the exit # code * 256 ...so divide, # and conquer print "***$errcode***\n"; #print it ( stands out doesnt it )
Well, thats it. I cant vote yet Tye, but you should be voted up for your reply. It led me to this code. I hope this helps.

- Have fun, XDB19

Replies are listed 'Best First'.
RE: Re: knowing if process dies.
by merlyn (Sage) on Aug 24, 2000 at 18:54 UTC
    Hmm. Dividing by 256 isn't quite right, because you could get a fractional number. Maybe this is closer:
    my $errcode = $? >> 8; my $core_was_dumped = !!($? & 128); my $signal_that_killed_it = $? & 127;
    This is from memory, so if I messed up, I'm sure someone will correct me. {grin}

    -- Randal L. Schwartz, Perl hacker