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?

5
  • Which Lua version are You using? Commented Oct 26, 2013 at 11:28
  • 5.1.4 on RHEL5_x86_64 platform Commented Oct 26, 2013 at 11:31
  • 3
    In Lua 5.2 you get the status. See lua.org/manual/5.2/manual.html#pdf-os.execute Commented Oct 26, 2013 at 13:09
  • @lhf I had try this under 5.2.2, but it does't return the correct value too. It returns true and exit Commented Oct 26, 2013 at 14:55
  • After exit there is a numerical exit code. Commented Oct 26, 2013 at 16:37

1 Answer 1

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);
  } 
Sign up to request clarification or add additional context in comments.

2 Comments

I gave it a try, but unfortunately it return 0 too.
Maybe stackoverflow.com/questions/10931134/… this related python question answers in part your question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.