Bash:将stdout从多个并发命令拆分为多个列 [英] Bash: Split stdout from multiple concurrent commands into columns

查看:71
本文介绍了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从多个并发命令拆分为多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆