furoshiki2
furoshiki2 copied to clipboard
furo2 exec does not treat standard input well
how to reproduce:
✘╹◡╹✘ < sh -c 'cat >/dev/null; test -t 0; echo $?' <<< "hello"
1
✘╹◡╹✘ < furo2 exec sh -c 'cat >/dev/null; test -t 0; echo $?' <<< "hello"
hello
0D
Because script(1) is designed for interactive shell and does not recognize standard input as well as other commands.
script is primarily designed for interactive terminal sessions. When stdin is not a terminal (for example: echo foo | script), then the session can hang, because the interactive shell within the script session misses EOF and script has no clue when to close the session. See the NOTES section for more information. You should also avoid use of script in command pipes, as script can read more input than you would expect.
http://man7.org/linux/man-pages/man1/script.1.html
(thanks @itchyny)
Maybe we should use subprocess package to execute given command instead of bypassing script(1).
Thanks, I agree that when stdin is not a terminal, we can simply use suprocess to capture output. I also think if the invoked command is an interactive one, we should use script(1).