【发布时间】:2018-03-27 17:05:43
【问题描述】:
我需要从 C++ 程序运行 Unix 命令。
string command;
do{
cout<<"~ "<<get_current_dir_name ()<<">";
cin>>command;
if(command=="exit"||cin.eof()){
cout<<"exit!"<<endl;
system("exit");
break;
}
system(command.c_str());
}while (true);
但是当我使用调用cd 命令(更改当前目录)时,我收到“权限被拒绝”错误。
我可以在我的代码中使用chmod 吗?如果是,我该如何使用它。
编译后我无法使用chmod。
这就是我编译代码的方式:
g++ -o shell *.cpp -std=c++11 -Wall -Wno-vla -pedantic -march=core2 -Os -pipe -fstack-protector-all -g3 -Wl,-O,1,-z,combreloc
【问题讨论】: