title: QProcess problems, output of process
body: <p>I am trying to figure out the use of QProcess.  I looked at Qt doc with no luck.<br />
  <a href="http://doc.qt.io/qt-4.8/qprocess.html" rel="nofollow noreferrer">http://doc.qt.io/qt-4.8/qprocess.html</a></p>
  <p><strong>EXAMPLES OF PROBLEM.</strong></p>
  <p><strong>Example 1:</strong> Code bellow works.</p>
  <pre><code>    #include &lt;QtCore/QCoreApplication&gt;
  #include &lt;QTextStream&gt;
  #include &lt;QByteArray&gt;
  #include &lt;QProcess&gt;    
  
  int main(int argc, char *argv[])
  {
      QCoreApplication a(argc, argv);
      QTextStream qout(stdout);    
  
      QProcess cmd;
      
      cmd.start(&quot;cmd&quot;);
      if (!cmd.waitForStarted())  {
          return false;
      }
  
      cmd.waitForReadyRead();
      QByteArray result = cmd.readAll();
      //qout &lt;&lt; result.data() &lt;&lt; endl;   //console junk captured, doesn't show. 
  
      //My test command
      cmd.write(&quot;echo hello&quot;);
      cmd.write(&quot;\n&quot;);
  
      //Capture my result
      cmd.waitForReadyRead();
      //This is my command shown by cmd, I don't show it, capture &amp; discard it.
      result = cmd.readLine();
      //Read result of my command (&quot;hello&quot;) and the rest of output like cur dir.   
      result = cmd.readAll();    
      qout &lt;&lt; result.data();
  
      qout &lt;&lt; &quot;\n\n---End, bye----&quot; &lt;&lt; endl;
      return a.exec();
  }
  </code></pre>
  <p>The <strong>output</strong> of the above code is</p>
  <blockquote>
  <p>hello</p>
  <pre><code>F:\Dev_Qt\expControllingExtConsoleApps-build-desktop&gt;
  
  ---End, bye----
  </code></pre>
  </blockquote>
  <p>The problem is that if I try to use ipconfig or 7zip in this fashion via Qprocess and cmd console, I am unable to see any output from ipconfig or 7zip.  I don't know if anything is even done, if something is done then why can't I see the output?  Code below illustrates.</p>
  <p><strong>Example 2:</strong>  Does not work.  Can't use ipconfig.</p>
  <pre><code>#include &lt;QtCore/QCoreApplication&gt;
  #include &lt;QTextStream&gt;
  #include &lt;QByteArray&gt;
  #include &lt;QString&gt;
  #include &lt;QProcess&gt;    
  
  int main(int argc, char *argv[])
  {
     QCoreApplication a(argc, argv);
     QTextStream qout(stdout);
     
     QProcess cmd2;
      cmd2.setWorkingDirectory(&quot;C:/Program Files/7-Zip&quot;);   //not needed in this example.
      cmd2.setReadChannel(QProcess::StandardOutput);
      cmd2.setProcessChannelMode(QProcess::MergedChannels);
  
      cmd2.start(&quot;cmd&quot;);
      if (!cmd2.waitForStarted())
      {
          qout &lt;&lt; &quot;Error: Could not start!&quot; &lt;&lt; endl;
          return false;
      }
  
      cmd2.waitForReadyRead();
      QByteArray result = cmd2.readAll();
      qout &lt;&lt; result.data() &lt;&lt; endl;      //Console version info, etc.
  
      //My command
      cmd2.write(&quot;ipconfig&quot;);
      cmd2.write(&quot;\n&quot;);
  
      //Capture output of ipconfig command
      //DOES NOT WORK!!
      cmd2.waitForReadyRead();
      while (! cmd2.atEnd())
      {
          result = cmd2.readLine();
          qout &lt;&lt; result;
          result.clear();
      }
      qout &lt;&lt; endl;
  
      qout &lt;&lt; &quot;\n\n---end----&quot; &lt;&lt; endl;
      return a.exec();
  
  }
  </code></pre>
  <p><strong>Output</strong> is below, it is missing the ipconfig connection information result. No output from ipconfig is captured at all.</p>
  <blockquote>
  <p>Microsoft Windows XP [Version
  5.1.2600] (C) Copyright 1985-2001 Microsoft Corp.</p>
  <p>C:\Program Files\7-Zip&gt; ipconfig</p>
  <p>---end----</p>
  </blockquote>
  <p>Should have been more like this (with ipconfig result).</p>
  <blockquote>
  <p>Microsoft Windows XP [Version
  5.1.2600] (C) Copyright 1985-2001 Microsoft Corp.</p>
  <p>C:\Documents and
  Settings\noname&gt;ipconfig</p>
  <p>Windows IP Configuration</p>
  <p>Ethernet adapter Local Area
  Connection:</p>
  <pre><code>    Connection-specific DNS Suffix  . :
      IP Address. . . . . . . . . . . . : 192.172.148.135
      Subnet Mask . . . . . . . . . . . : 255.255.255.0
      Default Gateway . . . . . . . . . : 192.172.148.177
  </code></pre>
  <p>C:\Documents and Settings\noname&gt;</p>
  </blockquote>
  <p>Obviously the output should should have been a little diff than above but the Connection info which is the output of &quot;ipconfig&quot; should have been captured.  In the same way if I try to use 7zip via cmd console... I can not see/capture any output of 7zip.  So my question is how can I use command line apps like ipconfig and 7zip via QProcess and cmd console and see the result of the output of these applications?</p>
  <p><strong>Example 3:</strong>  7zip does not work</p>
  <pre><code>#include &lt;QtCore/QCoreApplication&gt;
  #include &lt;QTextStream&gt;
  #include &lt;QByteArray&gt;
  #include &lt;QProcess&gt;    
  
  int main(int argc, char *argv[])
  {
     QCoreApplication a(argc, argv);
     QTextStream qout(stdout);
  
      QProcess cmd2;
      cmd2.setWorkingDirectory(&quot;C:/Program Files/7-Zip&quot;);
      cmd2.setReadChannel(QProcess::StandardOutput);
      cmd2.setProcessChannelMode(QProcess::MergedChannels);
  
      cmd2.start(&quot;cmd&quot;);
      if (!cmd2.waitForStarted()) {
          return false;
      }
  
      //My Command
      cmd2.write(&quot;7z.exe&quot;);
      cmd2.write(&quot;\n&quot;);
  
      //Capture output of ipconfig command
      cmd2.waitForReadyRead();
      QByteArray result;
  
      while (! cmd2.atEnd()) {
          result = cmd2.readLine();
          qout &lt;&lt; result;
          result.clear();
      }
      qout &lt;&lt; endl;
  
      qout &lt;&lt; &quot;\n\n---end----&quot; &lt;&lt; endl;
      return a.exec();
  }
  </code></pre>
  <p><strong>Output</strong> below. Does not show anything from 7zip.</p>
  <blockquote>
  <p>Microsoft Windows XP [Version
  5.1.2600] (C) Copyright 1985-2001 Microsoft Corp.</p>
  <p>C:\Program Files\7-Zip&gt;7z.exe</p>
  <p>---end----</p>
  </blockquote>
  <p>Output is expected to be along the lines of...</p>
  <blockquote>
  <p>Microsoft Windows XP [Version
  5.1.2600] (C) Copyright 1985-2001 Microsoft Corp.</p>
  <p>C:\Documents and Settings\noname&gt;cd
  C:\Program Files\7-Zip</p>
  <p>C:\Program Files\7-Zip&gt;7z.exe</p>
  <p>7-Zip 9.15 beta  Copyright (c)
  1999-2010 Igor Pavlov  2010-06-20</p>
  <p>Usage: 7z  [...]
  &lt;archive_name&gt; [&lt;file_names&gt;...]
  [&lt;@listfiles...&gt;]</p>
  <p>   a: Add files to archive<br />
  b: Benchmark   d: Delete files from
  archive   e: Extract files from
  archive (without using directory
  names)   l: List contents of archive<br />
  t: Test integrity of archive   u:
  Update files to archive   x: eXtract
  files with full paths <br />
  -ai[r[-|0]]{@listfile|!wildcard}: Include archives<br />
  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives   -bd: Disable
  percentage indicator<br />
  -i[r[-|0]]{@listfile|!wildcard}: Include filenames   -m{Parameters}:
  set compression Method<br />
  -o{Directory}: set Output directory   -p{Password}: set Password   -r[-|0]: Recurse subdirectories   -scs{UTF-8 |
  WIN | DOS}: set charset for list files
  -sfx[{name}]: Create SFX archive   -si[{name}]: read data from stdin   -slt: show technical information for l (List) command   -so: write data to
  stdout   -ssc[-]: set sensitive case
  mode   -ssw: compress shared files<br />
  -t{Type}: Set type of archive   -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]:
  Update options   -v{Size}[b|k|m|g]:
  Create volumes   -w[{path}]: assign
  Work directory. Empty path means a
  temporary directory<br />
  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames   -y: assume Yes on
  all queries</p>
  <p>C:\Program Files\7-Zip&gt;</p>
  </blockquote>