in reply to IPC::Open2, WinXP, Perl 5.6.1

Why do you expect open2 to die?
use strict; use IPC::Open2; use Carp; eval { open2(*RDRFH, *WTRFH, 'xxx'); }; if ($@) { if ($@ =~ /^open2/) { warn "open2 failed: $!\n$@\n"; return; } die; # reraise unforeseen exception } warn "HELLO BUDDY"; __END__ 'xxx' is not recognized as an internal or external command, operable program or batch file. HELLO BUDDY at - line 13.
Some RTFM is in order on your part (`perldoc IPC::Open2').

update: whoooops. I see why you thought that. But still, you should be checking the pid. open2() returns the process ID of the child process. It doesn't return on failure: it just raises an exception matching /^open2:/. However, exec failures in the child are not detected. You'll have to trap SIGPIPE yourself.

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re: Re: IPC::Open2, WinXP, Perl 5.6.1
by mrd (Beadle) on Feb 11, 2004 at 12:53 UTC
    Thanks for the response but, as I said I'm on Windows. Checking for SIGPIPE is not an option (I'm not using Cygwin).

    Also, as there is no exception being thrown, the pid is *always* set. I assume it is the shell's pid.

      Right. $^E and $? are still available.

      watch dem wheels turn

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

        Just what good are those going to do?

        The $? is the same as the pid returned by open2.

        $^E is a system-wide variable which can be set by any program running in the system (I'm on Windows remeber?). It's value is persistent across processes until somebody sets it to a new value (by causing some error). I cannot rely on that to check wether the call to open2 succeded or not. Also, $^E is never "reseted" or "unseted".

        The reality is that if open2 failes, no exception will be thrown and there is no way check for failure (until I actually try to read/write on those pipes, of course).