~ bash --version
GNU bash, version 3.2.51(1)-release (sparc-sun-solaris2.10)
Copyright (C) 2007 Free Software Foundation, Inc.
以下命令按预期工作:
~ ls hdfhdfhdhfd 2> >(wc -l)
1
...但这行不通,我已经没有办法弄清楚原因了:
~ truss -eaf bash -c 'true' 2> >( some command to process text)
>()
中的命令最终阻塞等待输入。
如果我这样做:
~ (true; truss -eaf bash -c 'true') 2> >( some command )
...它按预期工作,尽管这不起作用:
~ ( truss -eaf bash -c 'true') 2> >( some command )
# ^^^^^ ... note the 1st command is missing
如果我制作一些命令
= dd bs=1
,它会消耗并打印所有文本 truss 会在 stderr
上吐出,然后阻塞。
只有在 solaris 中使用 truss
时,我才能在 Linux 中重现类似的行为。
最佳答案
根据@ccarton 的回复,我对正在发生的事情有了一个大概的了解。举例说明:
~ truss -eaf /usr/bin/perl -e 'print "Test\n"; sleep 5' 2> >(dd bs=1 | wc -l)
在另一个终端我可以看到这个父/子层次结构:
庆典
truss -eaf/usr/bin/perl -e printf "Test\n";睡 5
/usr/bin/perl -e printf "测试\n";睡 5
庆典
dd bs=1
wc -l
truss
正在等待 shell,但是 dd
不会退出,直到它的标准输入被关闭...所以他们死锁了。
~ truss -eaf -o >(some command) another command
... 导致某些命令
在当前 shell 下执行,因此 truss
永远不是它的祖先。
我在 Linux 中看到了相同的层次结构,但它并没有死锁。
关于bash - 将 stderr 重定向到使用进程替换创建的子 shell 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16368118/