title: Redirecting output from gnome-terminal using QProcess in C++
body: <p>I am trying to generate a subprocess for a gui which will spawn a terminal. I want the data produced by this terminal (stdout and stderr) to be displayed on the window that appears as well as to a set log file. When I type the command directly in to a shell it works as intended, but when provided to a QProcess as a start command it doesn't actually write anything to the file.</p>
  
  <p>For example: if the user doesn't have the binaries installed it should write to bin.log that the command was not found. I have set my environment for the spawned QProcess to be the same as the running parent process (so that it can find bash and anything else), and have set the working directory before calling QProcess.start() method. I wrote a test case which follows:</p>
  
  <pre><code>gnome-terminal --title 'Sub-Terminal' -e 'bash -c "foo [args to foo] |&amp; tee foo.log"'
  </code></pre>
  
  <p>In Qt I do the following:</p>
  
  <pre><code>QProcess *child = new QProcess(this);
  QString   cmd   = "gnome-terminal --title 'Sub-Terminal' -e 'bash -c \"foo [args to foo] |&amp; tee foo.log\"'";
  child-&gt;setProcessEnvironment(&lt;process environment I have created before&gt;);
  child-&gt;setWorkingDirectory(&lt;current working dir&gt;);
  child-&gt;start(cmd);
  ...
  </code></pre>
  
  <p>It generates the terminal but does not write any data to foo.log. I have also tried the following:</p>
  
  <pre><code>QProcess *child = new QProcess(this);
  QString   prog  = "gnome-terminal"
  QStringList args;
  args &lt;&lt; "-x" &lt;&lt; "bash" &lt;&lt; "foo" &lt;&lt; "[foo's arguments]" &lt;&lt; "|&amp;" &lt;&lt; "tee" &lt;&lt; "foo.log";
  // set the process env and working dir
  child-&gt;start(prog, args);
  </code></pre>
  
  <p>Does anyone have any advice on how to solve this?
  I have tried redirecting stdout and stderr using QProcess.setStandardErrorFile(foo.log) and QProcess.setStandardOutputFile(foo.log), but it seems like that would be redirecting the stdout from the gnome-terminal itself (which isn't anything).</p>