in reply to How to know the status of a command invoked by open function?

this should be 0 as the command execution is succesful

The fine manual says you should only check $! (or $?) after a system call fails

open ... or die $!; close ... or die $!; print ... or die $!;
Its the only time the value of $!/$? is meaningful

Replies are listed 'Best First'.
Re^2: How to know the status of a command invoked by open function?
by ikegami (Patriarch) on Aug 16, 2011 at 00:43 UTC
    No. $? is only meaningful if the system call succeeds in this case, and it's always meaningful after wait, waitpid, system and backticks.
      See this from Perl.The.Complete.Reference.2nd.Edition.2001
      
      The close function, on the other hand, picks up any errors generated by
      the executed process because it monitors the return value received from the child
      process via wait (see the “Creating Child Processes” section, later in this chapter).
        Yes, I'm well aware of how it works.
      I know what the meaning of $?. but for my case. I used open to run an external program
      

        Yes, but the Anonymous Monk to which I replied didn't.

        He's right that close PS; should be close PS or die $!;, but it won't change the result.

        Note that by "system command", he meant "system calls", not the system builtin.