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

Greetings Monks,

I've read about the disadvantages of using IPC::Open2, but in my case it should be ok because, the communicating programs are all written by me and I can make sure that no OS buffering will stand in my way :)

Still, the following code snippet (mostly from perlipc) never raises an exception:

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 }
That 'xxx' program is of course not there and I would have expected $@ to be set. Instead $@ is empty so I can't do my error handling in this case.

I would appreciate a solution that does not involve additional CPAN modules or a more recent Perl.

My environment is described in the subject line.

Thanks your time.

Replies are listed 'Best First'.
Re: IPC::Open2, WinXP, Perl 5.6.1
by PodMaster (Abbot) on Feb 11, 2004 at 12:04 UTC
    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.

      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.