【发布时间】:2014-06-28 00:34:11
【问题描述】:
我想在 C 脚本中运行 ../folder1/folder2 中的可执行文件。现在我正在尝试做:
char command[50];
strcpy(command, "cd ../folder1/folder2");
system(command);
memset(command,0,sizeof(command));
strcpy(command, "./executable_name");
system(command);
但它不起作用。我应该使用 chdir(),还是有其他方法可以做到这一点?有可能吗?
【问题讨论】:
-
工作不
strcpy(command, "../folder1/folder2/executable_name"); system(command);? -
可能你没有访问某些文件夹
-
C 不是脚本语言;说“在 C 脚本中”听起来很奇怪。
-
此外,
system()会生成一个子shell 来执行您的命令,因此您的cd将仅适用于该子shell,该子shell 在为您的第二个命令创建新子shell 之前退出。
标签: c executable