如何捕获从 Powershell 运行的控制台 exe 的二进制标准输出?

发布于 2024-10-08 11:22:39 字数 224 浏览 0 评论 0原文

是否可以让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒的傷心 2024-10-15 11:22:39

从 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文