如何捕获从 Powershell 运行的控制台 exe 的二进制标准输出?
是否可以让 Powershell 将 exe 的标准输出读入 byte[] 而不是通常的文本处理行数组?
我能做的最好的事情就是:
cmd /c foo.exe > foo.tmp
$b = [io.file]::readallbytes('foo.tmp')
del foo.tmp
恶心,更不用说它不能流式传输。有更好的方法来做到这一点吗?
Is it possible to get Powershell to read the stdout of an exe into a byte[] instead of the usual text processed array of lines?
Best I've been able to do is this:
cmd /c foo.exe > foo.tmp
$b = [io.file]::readallbytes('foo.tmp')
del foo.tmp
Yucky, not to mention it is not streamable. Any better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 PowerShell 团队获取了一些信息。简而言之,不幸的是,这并不容易。 :-(
中等长度的答案是:http://poshcode.org/2175。
长答案是:< a href="http://www.pavleck.net/powershell-cookbook/ch02.html" rel="nofollow">捕获并重定向二进制进程输出
Got some info from the PowerShell team. The short answer is that unfortunately, it is not easy. :-(
The medium length answer is: http://poshcode.org/2175.
The long answer is: Capture and Redirect Binary Process Output