简体   繁体   English

Qprocess参数回声和管道

[英]Qprocess arguments echo and piping

I am trying to launch a CEC command in my Raspberry Pi (Raspbian) under a QProcess. 我试图在QProcess下的Raspberry Pi(Raspbian)中启动CEC命令。

if i execute in my shell this: 如果我在我的外壳中执行此操作:

echo 'standby 0' | cec-client -s

it is working, but if i put it inside a Qprocess with this: 它正在工作,但是如果我把它放在一个Qprocess中:

QProcess *proc = new QProcess;
proc->start("echo",{"'standby 0' | cec-client -s"});
proc->waitForFinished();

it is not executing as expecting. 它没有按预期执行。 Otherwise in my Raspberry Pi is workig well. 否则在我的Raspberry Pi中效果很好。 What am i doing wrong? 我究竟做错了什么?

The problem is you cannot run a system command with QProcess, but only a single process. 问题是您不能使用QProcess运行系统命令,而只能运行一个进程。 So the workaround will be to pass your command as an argument to bash: 因此,解决方法是将您的命令作为参数传递给bash:

process.start("bash", QStringList() << "-c" << "echo 'standby 0' | cec-client -s");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM