lua-users home
lua-l archive

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


Am 27.12.2013 22:58 schröbte Rob Kendrick:
On Fri, Dec 27, 2013 at 04:42:55PM -0500, Sean Conner wrote:
Am I missing something?

   It's Linux.

s/Linux/UNIX/

popen() passes the string you give it to the shell (most likely as set
in $SHELL in the environment);

or just `/bin/sh -c`.

it has no way of knowing if the arbitrary
line of shellscript you gave it was successful in running a program or
not.

But you can find out (in Lua 5.2) by calling the `close` method on the returned file pointer:

    > print( io.popen( "no_such_program" ):close() )
    sh: 1: no_such_program: not found
    nil     exit    127
    > print( io.popen( "false" ):close() )
    nil     exit    1
    > print( io.popen( "true" ):close() )
    true    exit    0


If you want reliability, you need a proper subprocess module that uses
fork/exec and executes the program directly.

B.


Philipp