in reply to Re^2: Opening not-existing command - Error Handling
in thread Opening not-existing command - Error Handling

This form of open starts a child process. The return result is the child process ID. Thus, your open(...) || die ... will show the error if the child can't be created. You need to check $? to check for errors from the child. See this for an example of checking for errors in this situation.

Replies are listed 'Best First'.
Re^4: Opening not-existing command - Error Handling
by Dirk80 (Pilgrim) on Aug 17, 2011 at 12:37 UTC

    Thanks. You are right. Examining $? helps to know if the child process executed correctly or not.

    Here my sample code:

    eval { open my $pipe, "perl --version |"; my @res = <$pipe>; close $pipe; }; print "Exit Status: " . ($?>>8);

    If I use the not existing command "perl2 --version" then I get the following error message and the exit status 1.

    Der Befehl "perl2" ist entweder falsch geschrieben oder konnte nicht gefunden werden. Exit Status: 1

    If I use an existing command like "perl --version" then I get the exit status 0 and no error message:

    Exit Status: 0

    Problem of course is that I then know the error not directly after the open, but only when the child process exited, that means after the close.