<p>How do I capture the output of "%windir%/system32/pnputil.exe -e"?
(assume windows vista 32-bit)</p>

<p>Bonus for technical explanation of why the app normally writes output to the cmd shell, but when stdout and/or stderr are redirected then the app writes nothing to the console or to stdout/stderr?</p>

<pre>
C:\Windows\System32>PnPutil.exe --help
Microsoft PnP Utility {...}

C:\Windows\System32>pnputil -e > c:\foo.txt

C:\Windows\System32>type c:\foo.txt

C:\Windows\System32>dir c:\foo.txt
 Volume in drive C has no label.
 Volume Serial Number is XXXX-XXXX

 Directory of c:\

09/10/2008  12:10 PM                 0 foo.txt
               1 File(s)              0 bytes
</pre>

[{'answer_id': 54588, 'author': 'chakrit', 'author_id': 3055, 'author_profile': 'https://Stackoverflow.com/users/3055', 'pm_score': 0, 'selected': False, 'text': '<p>Some applications are written so that it works in piping scenarios well e.g.</p>\n\n<pre><code>svn status | find "? "\n</code></pre>\n\n<p>is a command that pipes output of <code>svn status</code> into <code>find "? "</code> so it would filter subversion output down to unknown files (marked with a question mark) in my repos.</p>\n\n<p>Imagine if svn status would also output a header that says "Copyright ? 2009" That very specific header line would also show up. Which is <em>not</em> what I expect.</p>\n\n<p>So certain tools, like those of Sysinternals\' will write any header information <em>only</em> if it is printed directly to the command window, if any kind of redirection is detected, then those header information will not be written as by the reason above.</p>\n\n<p>Header information becomes noise when used in piping/automation scenarios.</p>\n\n<p>I suppose if you can\'t use <code>&gt;</code> to output to a file, its because the tool is hardwired not to do so. You\'ll need an indirect means to capture it.</p>\n\n<p>Hope this helps.</p>\n'}, {'answer_id': 54619, 'author': 'JeffJ', 'author_id': 5429, 'author_profile': 'https://Stackoverflow.com/users/5429', 'pm_score': 0, 'selected': False, 'text': '<p>As alluded to in the question, but not clearly stated, "pnputil -e 2> c:\\foo.txt" does not have the intended result either.  This one directs nothing into the file but it does send the output to the console.</p>\n'}, {'answer_id': 54662, 'author': 'Peter Ritchie', 'author_id': 5620, 'author_profile': 'https://Stackoverflow.com/users/5620', 'pm_score': 0, 'selected': False, 'text': '<p>There\'s only two output streams.  If "> c:\\foo.txt" doesn\'t work, and "2> C:\\foo.txt" doesn\'t work then nothing is being output.</p>\n\n<p>You can merge the standard error into the standard output (2>&amp;1) so all output is through standard output:</p>\n\n<p>pnputil -e 1>c:\\foo.txt 2>&amp;1</p>\n\n<p>If that doesn\'t output anything to foo.txt then pnputil must be detecting redirection and stopping output.</p>\n'}, {'answer_id': 54681, 'author': 'JeffJ', 'author_id': 5429, 'author_profile': 'https://Stackoverflow.com/users/5429', 'pm_score': 1, 'selected': False, 'text': "<p>I think I found the technical answer for why it behaves this way.  The MSDN page for WriteConsole says that redirecting standard output to a file causes WriteConsole to fail and that WriteFile should be used instead.  The debugger confirms that pnputil.exe does call kernel32!WriteConsoleW and kernel32!WriteConsoleInputW.</p>\n\n<p>Hmm, I should have asked this as two separate questions.</p>\n\n<p>I'm still looking for an answer for how to scrape the output from this command.  The accepted answer will be one that answers this part of the question.</p>\n"}, {'answer_id': 54862, 'author': 'Rob Walker', 'author_id': 3631, 'author_profile': 'https://Stackoverflow.com/users/3631', 'pm_score': 2, 'selected': True, 'text': '<p>Doesn\'t seem like there is an easy way at all.  You would have to start hooking the call to WriteConsole and dumping the string buffers.  See <a href="http://objectmix.com/tcl/366746-autoexpect-under-windows-later-mac-linux.html#post1359780" rel="nofollow noreferrer">this post</a> for a similar discussion.</p>\n\n<p>Of course, if this is a one off for interactive use then just select all the output from the command window and copy it to the clipboard. (Make sure you cmd window buffer is big enough to store all the output).</p>\n'}, {'answer_id': 665987, 'author': 'schlenk', 'author_id': 60725, 'author_profile': 'https://Stackoverflow.com/users/60725', 'pm_score': 0, 'selected': False, 'text': '<p>You could have tried Expect for Windows to do this kind of things, it would tell the tool that there was a console and hook the WriteConsole calls for you.\n<a href="http://docs.activestate.com/activetcl/8.5/expect4win/welcome.html" rel="nofollow noreferrer">Expect for Windows</a></p>\n'}, {'answer_id': 2457336, 'author': 'John Weinel', 'author_id': 295063, 'author_profile': 'https://Stackoverflow.com/users/295063', 'pm_score': 0, 'selected': False, 'text': '<p>Click on the system menu icon (upper left hand corner->properties->layout)</p>\n\n<p>Change the screen buffer size</p>\n\n<p>cls</p>\n\n<p>pnputil -e</p>\n\n<p>;-P</p>\n'}, {'answer_id': 8152245, 'author': 'Vardhan', 'author_id': 1049736, 'author_profile': 'https://Stackoverflow.com/users/1049736', 'pm_score': 1, 'selected': False, 'text': '<p>If you know the driver name and have the driver,\npnputil.exe -a d:\\pnpdriver*.inf</p>\n\n<p>This gives list of corresponding oemXX.inf for the drivers you are looking.</p>\n'}, {'answer_id': 46796987, 'author': 'Tim LaGrange', 'author_id': 8791813, 'author_profile': 'https://Stackoverflow.com/users/8791813', 'pm_score': 0, 'selected': False, 'text': '<p>So I am looking for the same type of information, and came across this:\n<a href="https://sysadminstricks.com/tricks/windows-tricks/cleaning-up-windows-driver-store-folder.html" rel="nofollow noreferrer">https://sysadminstricks.com/tricks/windows-tricks/cleaning-up-windows-driver-store-folder.html</a>.\nWhile the syntax is wrong, it seems to have done the trick for me (with a little correction):</p>\n\n<pre><code>pnputil.exe -e &gt; c:\\driveroutput.txt\n</code></pre>\n\n<p>When that command is executed, it does <em>not</em> output to the command line, but it does generate <code>driveroutput.txt</code> to the root of <code>C:</code>.\nOpening the text file does, in fact, show that I now have an output of the enumerated OEM drivers on my PC.</p>\n'}]
['https://Stackoverflow.com/questions/54578', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5429/']