【发布时间】:2013-04-01 19:14:34
【问题描述】:
我正在尝试在 C++ 中运行 execl(),但它失败了,我不确定为什么。
string fileName = "test.txt";
string computerName = "jssoile@palmetto.school.edu";
pid_t pid;
int status;
if ((pid = fork()) < 0) { /* fork a child process */
printf("*** ERROR: forking child process failed\n");
exit(1);
}
else if (pid == 0) { /* for the child process: */
if (execl("scp", fileName.c_str(), computerName.c_str(), NULL) < 0) { /* execute the command */
printf("*** ERROR: exec failed\n");
exit(1);
}
}
else { /* for the parent: */
while (wait(&status) != pid) /* wait for completion */
;
}
当我运行它时,我的 execl() 调用失败并打印出来
*** ERROR: exec failed
【问题讨论】:
-
您的帖子不包含问题;请编辑您的帖子。无论如何,请将您的
printf("*** ERROR: exec failed\n")替换为perror("scp")。
标签: c++ string character exec fork