c - 使用c编程运行shell脚本

标签 c shell system exec

大家好我想问我正在制作一个程序,我必须在其中使用 c 程序运行 shell 脚本。到目前为止,我已经将论点分开了。我已经搜索过 exec 应该用于运行 shell 脚本 但是我很困惑,因为 exec 有很多变体,通过阅读手册页我无法找到最合适的

同样在某些exec函数中第一个arg是

path

还有一些有

pointer to file

有什么区别,我应该写什么来代替它。请指导我 谢谢

最佳答案

从 C 程序运行 shell 脚本通常使用

#include <stdlib.h>
int system (char *s);

其中 s 是指向脚本路径名的指针,例如

int rc = system ("/home/username/bin/somescript.sh");

如果您需要脚本的标准输出,请查看 popen 手册页。

关于c - 使用c编程运行shell脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7724432/

相关文章:

c - 如何将 C 程序的字符串发送到 su 密码提示?

perl - String::ShellQuote: 我什么时候需要 `shell_quote` ?

ios - iPhone - 如果互联网可用或不可用,则捕获系统事件

c - Arch Linux 上的 OpenGL 3.3

java - Linux : How to check a file copy has finished in my watch folder?

node.js - 如何不以 root 身份安装全局?

linux - 在 2 个文件中查找匹配项并打印匹配项上方的字段

c - 如何编写根据命令行参数将字母转换为大写或小写的程序?

c - Ruby - 源代码 - 编码风格

c - 枚举错误,变量未声明