Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • Worked perfectly for me... I wanted to "massage" the output of 7zip while it was running, but it – seemingly – buffers its output if it is being piped. Using this put it back in "terminal mode" while still allowing the output to be piped. Commented Apr 10, 2020 at 16:37
  • This is the only solution out of many I've tried that both (1) preserves colors (from ANSI escape codes) in piped output, and (2) passes SIGINT (Ctrl+C) to the child process. Thank you! I did have to change the script's shebang to specify python3 to get it working. On my Mac, the default Python installation is Python 2, which produces a "'BrokenPipeError' is not defined" error. Commented Mar 19, 2021 at 3:24
  • Thank you, that seems to just work! (I use fishshell, so I tweaked it from os.execvp(argv[1], argv[1:]) to os.execvp('fish', ('fish',) + tuple([ '-c', ' '.join(argv[1:]) ])) so I can use my autoloading fish functions, and... that seems to work?) (And ubuntu 20.04 also needs a 3 added to the shebang.) (... and of course, you prolly need to mess around with like -r/-R flags when piping into less in order to get as close as possible to what you really want...) Commented Apr 3, 2021 at 12:53
  • If you're going to invoke a shell, you'll just have to remember to do extra escaping if one of the arguments going into python has spaces. Commented Apr 5, 2021 at 5:11
  • @Owen_AR see my edit for specifics. Commented Apr 6, 2021 at 20:47