【问题标题】:How to capture binary stdout of a console exe run from Powershell?如何捕获从 Powershell 运行的控制台 exe 的二进制标准输出?
【发布时间】:2010-12-19 05:26:29
【问题描述】:

是否可以让 Powershell 将 exe 的标准输出读入 byte[] 而不是通常的文本处理的行数组?

我能做的最好的就是:

cmd /c foo.exe > foo.tmp
$b = [io.file]::readallbytes('foo.tmp')
del foo.tmp

很糟糕,更不用说它不可流式传输了。有更好的方法吗?

【问题讨论】:

    标签: powershell


    【解决方案1】:

    从 PowerShell 团队获得了一些信息。简短的回答是,不幸的是,这并不容易。 :-(

    中等长度的答案是:http://poshcode.org/2175

    长答案是:Capture and Redirect Binary Process Output

    【讨论】:

    • 感谢您的跟进。我希望它不需要我在 C# 中必须做的那些令人讨厌的事情,但是很高兴代码已经在 poshcode 上可用。另外:你刚刚让 Lee Holmes 成为了一笔买卖。我正在拿起那本书的第二版。 :)
    • 这篇文章中的两个链接现在都失效了:(
    • 这里是 PowerShell Cookbook 的更新链接 - oreilly.com/library/view/powershell-cookbook-4th/9781098101596
    猜你喜欢
    • 1970-01-01
    • 2016-06-21
    • 2020-08-24
    • 2021-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    • 1970-01-01
    相关资源
    最近更新 更多