【发布时间】:2013-06-05 06:16:20
【问题描述】:
我想使用 C 文件中的代码更改 unix 中的目录。我试过这个:
char command[50];
strcpy( command, "cd newdirectory/" );
system(command);
但它没有工作。使用“系统”的其他命令工作。
【问题讨论】:
-
您的命令会起作用,但只能在
system()调用中起作用。即如果你这样做system("cd newdirectory && rm foo");,rm foo将发生在newdirectory。 -
@zmo 这就是问题所在。我不知道它可以执行命令但仍保留在当前目录中。您可以将其作为答案(正确)
标签: c linux bash shell directory