linux - 从 C++ 调用 shell 脚本

标签 linux bash shell

命令 execl("/system/bin/sh","sh","test.sh")

从 C++ 代码调用 shell 脚本 test.sh

执行 shell 脚本后,我需要将控制权交还给 C++,但 shell 脚本只是退出而不是执行 C++ 代码中的下一条指令

最佳答案

您想在exec 之前使用fork 创建一个子进程:

pid_t pid;
if((pid = fork()) == 0)
    execl("/system/bin/sh","sh","test.sh");
int status;
waitpid(pid, &status, 0); // wait for child process, test.sh, to finish

关于linux - 从 C++ 调用 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24386993/

相关文章:

linux - 在解析(即扩展)通配符时停止 Linux shell

c - Linux : pipeline output of one program to another

linux - 在 Linux 或 MacOS X 中将 20141207_190822.jpg 等文件重命名为 "2014-12-07 19.08.22.jpg"

c++ - 如何像 "top"linux 命令一样进行控制台输入?

linux - Bash脚本不删除给定目录中的文件

bash:遍历 txt 文件行无法读取最后一行

linux - 为什么 |不适用于查找?

bash - 为什么退出循环后我的数组消失了?

sql - 通过 Shell 脚本从 Oracle DB 中提取 Insert 语句

python - 在 SSH/Paramiko 中使用不同的 shell 执行命令/脚本