Piping (or command chaining) with QProcess

后端 未结 4 1414
轻奢々
轻奢々 2020-12-01 16:21

I\'m using Qt and bash over it, need to execute something like:

bash: cat file | grep string

in Qt:

QString cmd = \"cat fil         


        
4条回答
  •  失恋的感觉
    2020-12-01 17:04

    The problem is that when you call process->start(cmd), the commands following the the call to cat are all interpreted as arguments to cat, so the pipe is not doing what you're expecting. If you start with a call to bash with a parameter of a string, you should get what you want: -

    QString cmd = "bash -c \"cat file | grep string\"";
    

    Alternatively, you could just call "cat file" and do the search on the returned QString when you read the output from the QProcess

提交回复
热议问题