tags:

views:

942

answers:

11

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

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?

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
A: 

It could be that pnputil outputs to stderr instead of stdout.

Try pnputil -e 2> c:\foo.txt

Peter Ritchie
Nope - tried that myself.
ColinYounger
A: 

Some applications are written so that it works in piping scenarios well e.g.

svn status | find "? "

is a command that pipes output of svn status into find "? " so it would filter subversion output down to unknown files (marked with a question mark) in my repos.

Imagine if svn status would also output a header that says "Copyright ? 2009" That very specific header line would also show up. Which is not what I expect.

So certain tools, like those of Sysinternals' will write any header information only 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.

Header information becomes noise when used in piping/automation scenarios.

I suppose if you can't use > to output to a file, its because the tool is hardwired not to do so. You'll need an indirect means to capture it.

Hope this helps.

chakrit
A: 

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.

JeffJ
A: 

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.

You can merge the standard error into the standard output (2>&1) so all output is through standard output:

pnputil -e 1>c:\foo.txt 2>&1

If that doesn't output anything to foo.txt then pnputil must be detecting redirection and stopping output.

Peter Ritchie
A: 

Out of curiousity, does piping to the clipboard put anything useful on the clipbioard?

e.g. pnputil -e | clip

Peter Ritchie
A: 

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.

Hmm, I should have asked this as two separate questions.

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.

JeffJ
A: 

@[Peter Ritchie]: Piping to clip has the effect of clearing the clipboard and writing nothing to the console. Good try.

JeffJ
If it's just clearing the clipboard then clearly pnputil is not outputting anything in these circumstances.
Peter Ritchie
+1  A: 

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 this post for a similar discussion.

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).

Rob Walker
A: 

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. Expect for Windows

schlenk
A: 

Hi,

I am basically reopening this thread. I believe this is a practical problem to get the output of pnputil to a file for some other purpose but right now, it does not appear to work.

Is there someone who can assist. Any help is appreciated.

Regards, Naveen

A: 

click on the system menu icon(upper left hand corner->properties->layout

change the screen buffer size

cls

pnputil -e

;-P

John Weinel