windows 如何捕获“pnputil.exe -e”的输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to capture output of "pnputil.exe -e"
提问by JeffJ
How do I capture the output of "%windir%/system32/pnputil.exe -e"? (assume windows vista 32-bit)
如何捕获“%windir%/system32/pnputil.exe -e”的输出?(假设 windows vista 32 位)
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?
关于为什么应用程序通常将输出写入 cmd shell 的技术解释的奖励,但是当 stdout 和/或 stderr 被重定向时,应用程序不会向控制台或 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
采纳答案by Rob Walker
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 postfor a similar discussion.
似乎根本没有简单的方法。您必须开始挂钩对 WriteConsole 的调用并转储字符串缓冲区。有关类似的讨论,请参阅此帖子。
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).
当然,如果这是一次性使用的交互式使用,那么只需从命令窗口中选择所有输出并将其复制到剪贴板。(确保您的 cmd 窗口缓冲区足够大以存储所有输出)。
回答by JeffJ
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.
我想我找到了为什么它会这样表现的技术答案。WriteConsole 的 MSDN 页面说,将标准输出重定向到文件会导致 WriteConsole 失败,应该改用 WriteFile。调试器确认 pnputil.exe 确实调用了 kernel32!WriteConsoleW 和 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.
我仍在寻找有关如何从该命令中抓取输出的答案。接受的答案将是回答问题的这一部分的答案。
回答by Vardhan
If you know the driver name and have the driver, pnputil.exe -a d:\pnpdriver*.inf
如果您知道驱动程序名称并拥有驱动程序,则 pnputil.exe -ad:\pnpdriver*.inf
This gives list of corresponding oemXX.inf for the drivers you are looking.
这为您正在查找的驱动程序提供了相应的 oemXX.inf 列表。
回答by Tim LaGrange
So I am looking for the same type of information, and came across this: https://sysadminstricks.com/tricks/windows-tricks/cleaning-up-windows-driver-store-folder.html. While the syntax is wrong, it seems to have done the trick for me (with a little correction):
所以我正在寻找相同类型的信息,并遇到了这个: https://sysadminstricks.com/tricks/windows-tricks/cleaning-up-windows-driver-store-folder.html。虽然语法错误,但它似乎对我有用(稍加修正):
pnputil.exe -e > c:\driveroutput.txt
When that command is executed, it does notoutput to the command line, but it does generate driveroutput.txt
to the root of C:
.
Opening the text file does, in fact, show that I now have an output of the enumerated OEM drivers on my PC.
当执行该命令时,它不输出到命令行,但它确实产生driveroutput.txt
到的根C:
。事实上,打开文本文件确实表明我现在在我的 PC 上有枚举的 OEM 驱动程序的输出。
回答by schlenk
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
您可以尝试使用 Expect for Windows 来执行此类操作,它会告诉该工具有一个控制台并为您挂接 WriteConsole 调用。 期待 Windows
回答by John Weinel
Click on the system menu icon (upper left hand corner->properties->layout)
点击系统菜单图标(左上角->属性->布局)
Change the screen buffer size
更改屏幕缓冲区大小
cls
类
pnputil -e
pnputil -e
;-P
;-P
回答by chakrit
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.
是一个命令管道输出svn status
到find "? "
所以它会过滤在我的回购颠覆输出到未知文件(标有问号)。
Imagine if svn status would also output a header that says "Copyright ? 2009" That very specific header line would also show up. Which is notwhat I expect.
想象一下,如果 svn status 也会输出一个标有“Copyright ? 2009”的标题,那么这个非常具体的标题行也会显示出来。这不是我所期望的。
So certain tools, like those of Sysinternals' will write any header information onlyif 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.
因此,某些工具,例如 Sysinternals 的工具,只有在直接打印到命令窗口时才会写入任何标题信息,如果检测到任何类型的重定向,则不会像上述原因那样写入这些标题信息。
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.
希望这可以帮助。
回答by JeffJ
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.
正如问题中提到的,但没有明确说明,“pnputil -e 2> c:\foo.txt”也没有预期的结果。这个没有将任何内容定向到文件中,但它确实将输出发送到控制台。
回答by Peter Ritchie
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.
只有两个输出流。如果 "> c:\foo.txt" 不起作用,并且 "2> C:\foo.txt" 不起作用,则不会输出任何内容。
You can merge the standard error into the standard output (2>&1) so all output is through standard output:
您可以将标准错误合并到标准输出 (2>&1) 中,以便所有输出都通过标准输出:
pnputil -e 1>c:\foo.txt 2>&1
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.
如果这不会向 foo.txt 输出任何内容,则 pnputil 必须检测重定向并停止输出。