& /dev/null")) print(s-6ren">
gpt4 book ai didi

lua os.execute() 返回错误值

转载 作者:行者123 更新时间:2023-12-04 19:22:49 25 4
gpt4 key购买 nike

遇到问题:

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

但是当我在 bash 中键入 pgrep -f 'tail -F/opt/aaa' >&/dev/null ,然后调用 echo $? 它返回1. 以前有没有人遇到过这种情况,或者知道原因 ;-) 发生了什么事?

最佳答案

对我来说这似乎不是 Lua 问题,os.execute 只是包装对 system 的调用:

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

如果您尝试使用 C 替代方案,您的结果代码是否正确?

 #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);
}

关于lua os.execute() 返回错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19605979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com