0

I want to use QProcess to run a Linux command in my Qt project. My process has some arguments so I used the following code:

QString _strFileName = "/root/a.o";
QStringList _strListArguments;
_strListArguments << "-c" << "file " << _strFileName << " | grep ELF";
_processFile->start("bash", _strListArguments);
_processFile->waitForFinished();

The output is null. But when I replace the variable with a value, the output is OK and there is no error there.

_strListArguments << "-c" << "file /root/a.o | grep ELF";

How can I solve this?

Ilya
  • 4,583
  • 4
  • 26
  • 51
s.m
  • 209
  • 2
  • 7
  • 17

1 Answers1

4

Things like | grep ELF are shell expressions which are parsed and interpreted by the shell. In this particular case the shell spawns two processes, redirecting former's output into latter's input. If you want to do this programmatically, you need to run bash or whatever shell you use using QProcess and pass /root/a.o -c file | grep ELF as its argument. See man bash to find out necessary flag.

arrowd
  • 33,231
  • 8
  • 79
  • 110