1

This is a mystery encountered at work today. Note that this behavior seems to be specific to a binary that I do not know the contents of, but any ideas as to how this phenomenon could occur would be welcome. It's not of much consequence whether or not this mystery is solved, but it would be gratifying to know what could cause this. Basically, it looks like this:

With either of these two commands, mystderr contains the output that mybinary printed to stderr (desired behavior):

$ ./mybinary 3>&1 1>mystdout 2>&3 3>&- | cat > mystderr
$ ./mybinary 3>&1 1>mystdout 2>&3 3>&- | while read line; do echo "$line"; done | grep -P ".*"; done > mystderr

With either of these two commands, mystderr contains nothing, strace shows that perl/grep get the input but do not write to stdout:

$ ./mybinary 3>&1 1>mystdout 2>&3 3>&- | perl -pe '/.*/p' > mystderr
$ ./mybinary 3>&1 1>mystdout 2>&3 3>&- | grep -P ".*" > mystderr

Why does cat know what to do, but grep doesn't? Why does just feeding the lines through a bash loop cause grep to figure out what to do?

0 Answers0