c++ - 如何在 C++ 中打开和关闭子应用程序
问题描述
我正在为 ubuntu 编写一个 c++ 控制台应用程序,它充当速率表控制器来接收用户命令并通过 tcp 将它们发送到执行命令并返回信息(例如位置和速度)的表。
我编写了一个 js/electron 应用程序来充当位置和速度信息的 GUI。
我希望我的用户能够在控制台应用程序中输入“GUION”来打开 GUI。然后输入“GUIOFF”关闭它。使用system("cd rtgui; npm start");
我可以打开 GUI,它运行得非常好 - 但这不是最佳选择,因为我无法使用“GUIOFF”命令关闭它,因为相同的终端窗口再次无法访问(据我所知)。
我的问题是,有没有比system()
我可以访问同一个终端窗口来调用npm start
然后npm stop
在用户需要时杀死 GUI 更好的方法?
命令代码在这里。
/*************************************************
appCommand - checks if the input is a command for this app.
*************************************************/
bool control::appCommand(string userInput){
// TODO - RUN THIS COUT IN DEBUG MODE ONLY
//printf("\nchecking command: %s\n", userInput.c_str());
// if "HELP" send help list and return true
if(userInput == std::string("HELP")){
helpSection();
return true;
} // if the gui is not enabled, populate it and switch the bool to true
else if(userInput == std::string("GUION")){
if(guiEnabled == false){
printf("\nEnabling GUI.\n");
system("cd rtgui; npm start");
// switch bool
guiEnabled = true;
}
// is an app command
return true;
} // if the gui is showing, close it.
else if(userInput == std::string("GUIOFF")){
if(guiEnabled == true){
printf("\nDisabling GUI.\n");
// TODO - Enter PROPER code to close GUI here.
system("cd rtgui; npm stop");
// switch bool
guiEnabled = false;
}
// is an app command
return true;
}
else if(userInput == string("QUIT")){
// We want to close connections - set connected to false.
isConnected = false;
// is an app command
return true;
}
return false;
}
解决方案
推荐阅读
- python - Beautiful Soup 去掉标签
- database - 为什么 LevelDB 的下层比上层大 10 倍?
- r - `lapply` 是否可以在“超时”约束下返回部分处理结果?
- google-apps-script - Google Apps Script Add On google.run.script 作为开发者运行?
- angularjs - Node-Red:仪表板模板 UI 中的 AngularJs 地理位置
- xmpp - 如何从命令行创建 XMPP 会话?
- c# - 事件溯源 - 处理批量事务
- java - 我是否为每个实例变量编写 javadoc 注释?
- python - Pandas.DataFrame.Apply - TypeError:'float' 类型的参数不可迭代
- python - API 调用未异步运行