Bash:将stdout从多个并发命令拆分为多个列

编程入门 行业动态 更新时间:2024-10-28 10:37:12
本文介绍了Bash:将stdout从多个并发命令拆分为多个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用单个&符在bash脚本中运行多个命令,如下所示:

I am running multiple commands in a bash script using single ampersands like so:

commandA & commandB & commandC

它们每个都有自己的stdout输出,但它们都混合在一起并在不连贯的混乱中淹没了控制台.

They each have their own stdout output but they are all mixed together and flood the console in an incoherent mess.

我想知道是否有一种简单的方法可以使用column命令或类似方法将其输出通过管道传输到自己的列中. IE.像这样:

I'm wondering if there is an easy way to pipe their outputs into their own columns... using the column command or something similar. ie. something like:

commandA | column -1 & commandB | column -2 & commandC | column -3

这种东西是新手,但从最初的挖掘看来,它似乎是 pr 可能是机票吗?或column命令...?

New to this kind of thing, but from initial digging it seems something like pr might be the ticket? or the column command...?

推荐答案

很遗憾地回答了我自己的问题.

Regrettably answering my own question.

所提供的解决方案都不是我要找的.因此,我开发了自己的命令行实用程序: multiview .也许其他人会受益?

None of the supplied solutions were exactly what I was looking for. So I developed my own command line utility: multiview. Maybe others will benefit?

通过将进程的stdout/stderr传递到命令界面,然后启动查看器"以查看其在列中的输出来工作:

It works by piping processes' stdout/stderr to a command interface and then by launching a "viewer" to see their outputs in columns:

fooProcess | multiview -s & \ barProcess | multiview -s & \ bazProcess | multiview -s & \ multiview

这将显示其输出的整齐的列视图.您也可以通过在-s标志之后添加一个字符串来命名每个进程:

This will display a neatly organized column view of their outputs. You can name each process as well by adding a string after the -s flag:

fooProcess | multiview -s "foo" & \ barProcess | multiview -s "bar" & \ bazProcess | multiview -s "baz" & \ multiview

还有其他一些选择,但这就是要点.

There are a few other options, but thats the gist of it.

希望这会有所帮助!

更多推荐

Bash:将stdout从多个并发命令拆分为多个列

本文发布于:2023-07-06 20:34:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1054510.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   命令   Bash   stdout

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!