[英]Garbled shell newlines after concurrent script execution
I'm attempting to execute a shell script concurrently from a makefile and have all of the output go to stdout though when I do, the newlines become garbled and the only reliable fix I've found is to reset
. 我正在尝试从makefile并发执行shell脚本,并将所有输出发送到stdout,尽管当我这样做时,换行符变得乱码,而我发现的唯一可靠的解决方法是reset
。
makefile: 生成文件:
all: t1 t2 t3 t4
t1 t2 t3 t4:
@./test.sh true
test.sh: test.sh:
#!/bin/bash
script -q /dev/null "$@" 2>&1 > /dev/null 2>&1
Invocation: 调用:
$ make -j
No output as you would expect, but sometimes it breaks the terminal and I have to reset
. 没有输出,正如您期望的那样,但是有时会损坏终端,我必须reset
。
Sometimes newlines and carriage returns don't work after it runs: 有时,换行符和回车符在运行后不起作用:
Devbox:Desktop user$ time make -j
real 0m0.019s
user 0m0.019s
sys 0m0.022s
Devbox:Desktop user$
Removing script
from the script and replacing that line with "$@"
allows it to work just fine, but I'm using script to preserve color output from the command. 从脚本中删除script
,并用"$@"
替换该行,可以使其正常工作,但我使用脚本来保留命令的颜色输出。
LOG=$(script -q /dev/null "$@" 2>&1 | tr -d '\r' | cat)
I think script
isn't the proper program here. 我认为script
在这里不合适。 I once gave an answer how to trick programs to do colorized output, even when their output goes not to a terminal using LD_PRELOAD
and an overwritten version of the glibc function isatty()
. 我曾经给出一个如何欺骗程序以进行彩色输出的答案 ,即使它们的输出不使用LD_PRELOAD
和glibc函数isatty()
的覆盖版本发送到终端。
Based on that, your test.sh
could look like this: 基于此,您的test.sh
可能如下所示:
#!/bin/bash
output=$(LD_PRELOAD=./libisatty.so $@)
return_value=$?
echo -e "$output"
exit $return_value
And your Makefile
like this: 和你的Makefile
是这样的:
all: t1 t2 t3 t4$
t1 t2 t3 t4:$
^I@./test.sh ls -al --color=auto$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.