3

have a problem:

 local stat = assert(os.execute("/usr/bin/pgrep -f 'tail -F /opt/aaa' >& /dev/null"))
 print(stat)  --> 0

But when I type pgrep -f 'tail -F /opt/aaa' >& /dev/null in bash, and then call echo $? it returns 1. Has anybody encountered this before, or know the reason why ;-) what happened?

ms2008
  • 362
  • 4
  • 19

1 Answers1

3

Doesn't seem to be a Lua problem to me, os.execute is just wrapping a call to system:

 static int os_execute (lua_State *L) {
    lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
    return 1;
 }

If you try the C alternative you have the correct result code?

 #include <stdio.h>
 #include <string.h>

 int main ()
 {
    char command[100];
    int result;

    strcpy( command, "/usr/bin/pgrep -f 'tail -F /opt/aaa' >& /dev/null" );
    result = system(command);

    return(0);
  } 
guilespi
  • 4,672
  • 1
  • 15
  • 24
  • I gave it a try, but unfortunately it return 0 too. – ms2008 Oct 26 '13 at 14:05
  • Maybe http://stackoverflow.com/questions/10931134/return-value-of-system-function-call-in-c-used-to-run-a-python-program?rq=1 this related python question answers _in part_ your question – guilespi Oct 26 '13 at 14:14