我有一个小型 C 程序调用 shell 脚本 myScript.sh。我得到的 ret 值为 256。请帮助我了解系统调用出了什么问题?
int main()
{
int ret;
ret = system (myScript.sh);
ret >>= ret;
if (ret != 0)
{
printf("ret is [%d]",ret);
}
}
在 64 位 UNIX 操作系统上工作并使用 ksh shell
最佳答案
在我的系统上,man system
说:
The system() function returns the exit status of the shell as returned by waitpid(2), or -1 if an error occurred when invoking fork(2) or waitpid(2). A return value of 127 means the execution of the shell failed.
waitpid
手册页描述了一组宏,例如从返回值中提取实际退出代码的 WEXITSTATUS()
。
我不太确定你打算用 ret >>= ret
做什么,但那是不对的。
关于C程序调用shell脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4187908/