【发布时间】:2021-02-12 09:20:08
【问题描述】:
我已经派生了一个子进程,然后使用execv 调用 bash 脚本,就像我将命令行参数传递给脚本一样,它不会在脚本内执行echo $1 时打印第一个参数。
std::string s = std::to_string(c_no);
char *args[] = {(char *)s.c_str(), NULL};
pid_t pid = fork();
if(pid == 0){
execv("./ckpnt.sh", &args[0]);
}
将c_no 视为任何整数。
这样做的正确方法是什么?
我已经引用了这个链接How to pass command line arguments from C program to the bash script?,但是这个答案使用了system系统调用,我尽量不使用它。
【问题讨论】:
标签: c++ bash fork exec command-line-arguments