文章目录
1.C++实现
下面是封装好的C++头文件,直接调用run_cmd_fun()即可。
#ifndef GET_CMD_H
#define GET_CMD_H
#endif // GET_CMD_H
#include <iostream>
#include<QString>
using namespace std;
//system("gnome-terminal --window -e 'bash -c \"pwd;ls;exec bash\"' --tab -e 'bash -c \"pwd; exec bash\"'");
QString win_cmd = "gnome-terminal --window -e 'bash -c \""; // 运行窗口的命令
QString tab_cmd = " --tab -e 'bash -c \""; //运行标签的命令
QString pause_cmd = ";exec bash\"'"; //终端等待的命令
QString source_path = "source /opt/ros/noetic/setup.bash ;"; //添加环境变量
QString Qcmd = "";
void run_cmd_fun(QString cmd1)
{
//get one cmd
Qcmd = "";
Qcmd.append(win_cmd);
Qcmd.append(source_path);
Qcmd.append(cmd1);
Qcmd.append(pause_cmd);
string cmd = Qcmd.toStdString();
cout << cmd << endl;
system(cmd.c_str());
}
void run_cmd_fun(QString cmd1, QString cmd2, int input_time=1)
{