好的,所以我正在使用 qt-C++ 程序从我的主机系统执行我的 SBC6845 中存在的程序 ./led.sh。该程序基本上将我的 SBC 连接到我的主机系统。它相当于“ super 终端”或“Minicom”。我从 http://code.google.com/p/qextserialport/ 中的“qextserialport-1.2rc.zip”中获得了这个程序(示例代码)“uartassistant” .
我看到了这个链接:Running shell command in QT c++ in ubuntu ,同时搜索如何从 qt 程序内部执行 shell 命令。我尝试并成功执行了./led.sh。感谢链接。
我声明
void someaction(); // in the dialog.h
然后在 dialog.cpp 中添加这个
connect(ui->pushButton, SIGNAL(clicked()), SLOT(someaction()));
还有这个
void Dialog::someaction()
{
QString command = "sh ./led.sh\r\n"; const char* command2;
command2 = command.toLocal8Bit().data();
port->write(command2);
我能够在我的 SBC 中制作 ledflash。
但是当我试图停止./led.sh时,问题出现了,我无法在uartassistant中这样做(错误,需要修改,仍然有效)。 但目前我正在尝试制作另一个 pushbutton_1 并在其中放入类似“Ctrl+Z”的内容并要求 ./led.sh 停止。 我遇到了一些其他链接,由于声誉低,我无法放置。 我不知道如何在 qt 应用程序中使用 SIGTERM/kill 选项[来自其他链接]并在单击按钮时执行。 假设我使用 kill,我将如何确定多个此类按钮操作的 pidof 并指定要杀死的人。
此外,我想补充一点,我的 SBC 有 ash [Almquist shell]。所以它是 Bourne shell 的低内存克隆,我不知道它是否支持退出 led.sh 的正常命令。
最佳答案
I have no idea how to use SIGTERM / kill option[from other links] inside qt app and execute on pushbutton click.
与这么多一样,Qt 为您提供了一个直观的抽象,让您不必担心任何这些,即 QProcess .在你的情况下你会想要这样的东西:
QProcess proc;
proc.start("led.sh");
...
//handle Ctrl-Z event
proc.close();
第一个答案here还有其他几种技术可以执行更复杂的 shell 命令。
关于c++ - 如何停止在不同系统的 shell 中运行的进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15766416/