Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用c++; 我需要从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);_C++_Shell_Unix_System - Fatal编程技术网

使用c++; 我需要从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);

使用c++; 我需要从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);,c++,shell,unix,system,C++,Shell,Unix,System,system()函数启动一个新的shell。如果在该shell中使用cd,则只会影响该shell,一旦对system()的调用返回,该shell就会消失,因此基本上没有效果。在C++程序中,你可能永远不应该使用系统()/Cuffe。如果你想改变你的执行代码的工作目录,你应该使用 CHDIR()/函数,这是POSIX,但是我相信在Windows上也可用。> P> Stand()> /Cuff>函数启动一个新的shell。如果在该shell中使用cd,则只会影响该shell,一旦对system()

system()
函数启动一个新的shell。如果在该shell中使用
cd
,则只会影响该shell,一旦对
system()
的调用返回,该shell就会消失,因此基本上没有效果。在C++程序中,你可能永远不应该使用<代码>系统()/Cuffe。如果你想改变你的执行代码的工作目录,你应该使用<代码> CHDIR()/<代码>函数,这是POSIX,但是我相信在Windows上也可用。

> P> <代码> Stand()> /Cuff>函数启动一个新的shell。如果在该shell中使用

cd
,则只会影响该shell,一旦对
system()
的调用返回,该shell就会消失,因此基本上没有效果。您可能不应该在C++程序中使用<代码> Stand()/Cyto>——如果您想改变执行代码的工作目录,则应该使用<代码> CHDIR()/<代码>函数,这是POSIX,但我相信也可以在Windows ./P>上使用。