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

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).

  • Comment on Re: Re: Re: Re: IPC::Open2, WinXP, Perl 5.6.1

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: IPC::Open2, WinXP, Perl 5.6.1
by PodMaster (Abbot) on Feb 11, 2004 at 18:10 UTC
    The $? is the same as the pid returned by open2.

    So what? According to the docs (perlvar, etc) it should have the info you need.

    $^E is not system wide and you can set it to whatever you want whenever

    E:\>perl -le"warn $^E;$^E=1;warn $^E;undef $^E;die $^E" Warning: something's wrong at -e line 1. Incorrect function at -e line 1. Died at -e line 1.
    You can always try your hand at IPC::Run3. I can't wait to see what you come up with.

    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.

      Perhaps I wasn't very clear in my OP about what I'm trying to do. Blame it on my bad English.

      Here is a second try.

      I want to use pipes to read something from a small program on my system. Currently there is no way I can tell whether there was nothing to read (ie. that program wrote nothing on STDOUT or STDERR) or there was an error opening those pipes. In the second case, I would like to give the user a hint about the problem.

      In other words, I have to take a different action based on whether there was an error or not. I think this is the recommended way to do programming :)

      So what? According to the docs (perlvar, etc) it should have the info you need.

      No. Quote from IPC::Open2:

       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.
      

      On Windows at least, that "child process" is the shell. This means that the call to open2 is always succesful! $? contains no information whatsoever about my other child process (ie. the program I'm trying to communicate with). Also, since this is Windows (no cygwin) I cannot trap SIGPIPE. Hence, no error handling is possible.

      Of course, this is all documented in IPC::Open2 and perlipc but it really took me some trial-and-error doing on my own to actually grok that info. I suppose an additional note in there would have been a real time saver.

      $^E is not system wide

      You are right of course. My mistake.

      You can always try your hand at IPC::Run3.

      Thanks for the tipp. Will take a look.