在有的时候,需要在程序里面启动shell脚本,当程序中满足相应的判断后,自动启动shell脚本
方法一(推荐):
std::string shell="shell文件绝对路径";
popen(shell.c_str(),"r");
例如:
std::string shell1="/home/amov/shell1.sh";
popen(shell1.c_str(),"r");
std::string shell2="/home/amov/shell2.sh";
popen(shell2.c_str(),"r");
方法二:
system("gnome-terminal -- bash -c 'shell命令'")
该命令的作用是新开一个终端,在终端执行相应的shell命令,shell命令可以是单独的一条命令,也可以启动一个脚本
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)