On Tue, 2005-01-25 at 11:34, Uri Guttman wrote:
> >>>>> "GL" == Greg London <[EMAIL PROTECTED]> writes:

>   GL> After the system call, how do I test for a control-c
>   GL> as the cause for the command ending?
> 
> look at $@ and check for why the process died. you can extract a signal
> number from it (shift 8 bits and mask IIRC, rtfm for details. i think
> perlvar covers it).

This is incorrect. $@ is for eval, $? is for system.

>   GL> Oh, and I can't simply say
> 
>   GL> system('cp -r longtree dest')==0 or die $@;
> 
>   GL> because some system commands will fail because the
>   GL> directory doesn't exist or something, and in those
>   GL> cases, I want the script to keep going.
> 
> just check for SIGINT and handle that.

You're correct, but that's not clear to the uninitiated. Here's the
explanation:

$? contains the exit status of the program. On POSIX-compliant systems
this is a number which is:

        ($exit << 8) | $signal

Where $exit is the parameter that the program passed to exit(2), and
$signal is the signal that interrupted the process, if any.

You can check to see if the process was killed by:

        if ($? & 0xff) {
                die "Process killed by signal ".($? & 0xff);
        } elsif ($? >> 8) {
                die "Process exited with status ".($? >> 8);
        } else {
                # Worked fine
        }

Make sense?

This is also a faq, so you can type:

        perldoc -q control-c

to see what the lord of the FAQ says ;-)


-- 
â 781-324-3772
â [EMAIL PROTECTED]
â http://www.ajs.com/~ajs

 
_______________________________________________
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to