Cannot execute echo command in QProcess

后端 未结 2 1469
北恋
北恋 2020-12-21 18:46

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         


        
2条回答
  •  没有蜡笔的小新
    2020-12-21 19:23

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

    There are a few ways to tackle this: -

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

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

    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);
    

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

提交回复
热议问题