在C++程序中启动shell脚本

在C++程序中启动shell脚本,第1张

文章目录 前言

前言

在有的时候,需要在程序里面启动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命令可以是单独的一条命令,也可以启动一个脚本

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/927353.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-17
下一篇 2022-05-17

发表评论

登录后才能评论

评论列表(0条)

保存