11

in bash I have some jobs running, in background. They are always producing random irrelevant error messages that pollute the terminal. I am not always so prompt to start them with the 2>&1 > /dev/null redirect. How can I redirect the output when they are already running?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
fstab
  • 890
  • See this related answer: http://unix.stackexchange.com/a/4035/74516 (not tested). – vinc17 Nov 30 '14 at 01:19
  • 1
    Thanks. Actually this command solved my problem in the most straightforward way: https://github.com/jerome-pouiller/reredirect/ – fstab Nov 30 '14 at 01:31
  • @fstab You can write that as an answer to your own question. I know I didn't know it was possible to do this (attaching to the target program as a debugger is quite a nice hack!), so I thank you for mentioning it. – Celada Nov 30 '14 at 04:07

1 Answers1

12

Bash can't modify the file descriptors of a running process.

See answers for How to change the output redirection of a running process? (or a similar thread on stackoverflow)

The easiest and only current tool seems to be reredirect:

reredirect is a utility for taking an existing running program and attaching its outputs (standard output and error output) to files or another process. (quoting project homepage)

reredirect -m /dev/null <PID>