无法在QProcess中执行echo命令 [英] Cannot execute echo command in QProcess

查看:206
本文介绍了无法在QProcess中执行echo命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在带有Qt的Ubuntu 10.04 LTS下使用netcat实用程序在我的设备中启动SCPI命令。我的代码如下:

I want to launch a SCPI command in my device using netcat utility under Ubuntu 10.04 LTS with Qt. My code looks like:

env = "echo TRIG | nc 192.168.1.100 23 -q1";
process1.execute(env);
process1.waitForFinished(1000);

此命令不返回任何数据,而只是触发数据获取。
如果将终端使用相同的 echo TRIG | nc 192.168.1.100 23 -q1命令,则一切正常。
从Qt,它不起作用。调试输出为 TRIG | nc 10.0.3.250 23 -q1 ...因此没有 echo。我的设备没有收到TRIG命令。

This command does not return any data but simply triggers the data acquisition. If using terminal with same "echo TRIG | nc 192.168.1.100 23 -q1" command, everything works fine. From Qt, it does not work. The debug output is "TRIG | nc 10.0.3.250 23 -q1" ... so without an "echo". My device does not receive the TRIG command.

您能告诉我我做错了什么吗?
非常感谢。

Could you please advise what I'm doing wrong? Many thanks.

推荐答案

您不能以这种方式在QProcess中使用管道命令(|)。

You can't use the pipe command (|) with QProcess that way.

有几种解决方法:-

您可以调用第一个命令并检索其输出

You can call the first command and retrieve its output before processing it either in Qt or with another call to QProcess.

或者,创建一个从QProcess调用的脚本并检索输出。

Or, create a script that you call from QProcess and retrieve the output.

最后,假设您使用的是Linux / OSX,则可以使用/ bin / bash调用QProcess并将命令传递给它。例如:-

Finally, assuming you're using linux / OSX, you can call QProcess with /bin/bash and pass the command to that. For example: -

env = "/bin/bash \"echo TRIG | nc 192.168.1.100 23 -q1\"";
process1.execute(env);

您可能会找到与Windows的/ bin / bash等效的文件,也许是cmd.exe

You can probably find an equivalent to /bin/bash for windows, perhaps cmd.exe

这篇关于无法在QProcess中执行echo命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆