我正在尝试在 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