将两个标准输出通过管道传输到标准输入的基础知识

发布于 2024-10-12 22:36:57 字数 526 浏览 6 评论 0原文

说到管道,我有点陌生。我想要做的(在 Windows PC 上,但我猜它与 UNIX 相同)是这样的:

(output.exe "second part" & output.exe "first part") | someapp.exe -

我被告知我

无法多次写入标准输出

一个类似的 unix 示例可能是:

(echo -n part2 & echo -n part1) | md5

它执行我想要的操作(原则上)。

从表面上看,是“output.exe”应用程序发出了警告(如果在没有 | someapp.exe - 的情况下运行,则输出仍然存在)。要么这只是运气不好,要么我错过了一些我不理解的管道的关键基础知识。

output.exe 给出的输出可以被 someapp.exe 附加和理解。有没有办法让两个output.exe一次输出一个到stdout?

I'm a bit green when it comes to piping. What I'm trying to do (on a Windows PC, but I'd guess it's the same as for UNIX) is this:

(output.exe "second part" & output.exe "first part") | someapp.exe -

I'm told that I

can't write to stdout multiple times

A similar unix example could be:

(echo -n part2 & echo -n part1) | md5

which does what I want (in principle).

From the looks of it it's the "output.exe" app which gives the warning (if run without | someapp.exe -, the output remains). Either this is just bad luck, or I'm missing some key fundamental of piping which I don't understand.

the output which output.exe gives can be appended and understood as such by someapp.exe just fine. Is there some way to have the two output.exe output to stdout one at a time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

隱形的亼 2024-10-19 22:36:57

奇怪,我的windows7下好像可以用。我编写了几个测试程序,一切都如您所期望的那样工作

C:\tmp>( output.exe part1 & output.exe part2 ) | input.exe
LINE[0]: ARG[0]: output.exe
LINE[1]: ARG[1]: part1
LINE[2]: ARG[0]: output.exe
LINE[3]: ARG[1]: part2

所以也许问题实际上出在您的output.exe或someapp.exe程序中?我在 Win7 和 WinXP 上进行了测试 我的程序在这里: http://min.us/mvphIUz

注意: &似乎在 Windows 中看起来像 ;在unix中。即分隔顺序运行的命令。如果您使用 &在 UNIX 中,它们都会同时运行,并且输出会很混乱。

Strange, looks like it works for me on windows7. I whacked up a couple of test programs and it all worked as you'd expect

C:\tmp>( output.exe part1 & output.exe part2 ) | input.exe
LINE[0]: ARG[0]: output.exe
LINE[1]: ARG[1]: part1
LINE[2]: ARG[0]: output.exe
LINE[3]: ARG[1]: part2

So maybe the problem is actually in your output.exe or someapp.exe programs? I tested on both Win7 and WinXP My programs are here: http://min.us/mvphIUz

NOTE: That the & seems in windows appears to work like the ; in unix. That is delimits the commands that are run sequentually. If you used & in unix they would all be run concurrently and the output would be jumbled.

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