C程序调用shell脚本

Sac*_*iya 3 c shell

我有一个小的C程序调用shell脚本myScript.sh.我得到ret的值为256.请帮助我知道系统调用出了什么问题?

int main()
{
int ret;
ret = system (myScript.sh);
ret >>=  ret;
if (ret != 0)
{
  printf("ret is [%d]",ret);
}
}
Run Code Online (Sandbox Code Playgroud)

使用64位UNIX操作系统并使用ksh shell

Gre*_*ill 5

在我的系统上,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.
Run Code Online (Sandbox Code Playgroud)

waitpid手册页介绍了一组宏等WEXITSTATUS()的萃取物从返回值实际的退出代码.

我不太确定你打算做什么ret >>= ret,但这不可能是正确的.