lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Thu, Feb 10, 2011 at 9:36 AM, Roberto Ierusalimschy
<> wrote:
> Is this second returned value any useful? Even if the child process
> running the command terminates with a signal, the shell running it will
> terminate normally, and that will be the status returned by pclose.
> It seems that almost always the type of exit will a "normal" exit.

Are you talking about this value?

       The  pclose() function waits for the associated process to
terminate and returns the exit
       status of the command as returned by wait4(2).
        - man popen(3)

dash is /bin/sh on ubuntu, and it says this in the man page:

     Errors that are detected by the shell, such as a syntax error,
will cause the shell to exit
     with a non-zero exit status.  If the shell is not an interactive
shell, the execution of
     the shell file will be aborted.  Otherwise the shell will return
the exit status of the
     last command executed, or if the exit builtin is used with a
numeric argument, it will
     return the argument.

And that seems to be the case:

% /bin/sh -c "/bin/true"; echo $?
% /bin/sh -c "/bin/false"; echo $?
% /bin/sh -c "exit 3"; echo $?

Also, the 127 return value (command not found), is invaluable for