C程序调用shell脚本

标签 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);
}
}

在 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/

相关文章:

bash - 如何在单引号内扩展变量?

shell - 查找、grep 和执行 - 合而为一?

linux - 在 Linux 上以另一个用户身份运行脚本

c - 我不明白我的逻辑有什么问题,导致我的一些输出正确和不正确

ios - 如何在 iOS 运行时确定 ARMv8 功能?

ruby - 将文件读入内存的unix实用程序?

bash - 打印所有列,但首先由模式分隔,bash

php - zend 引擎返回对象引用

c - 将节点添加到全局链表导致崩溃

c - 链接列表 - 错误