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?
-
See this related answer: unix.stackexchange.com/a/4035/74516 (not tested).– vinc17Nov 30, 2014 at 1:19
-
1Thanks. Actually this command solved my problem in the most straightforward way: github.com/jerome-pouiller/reredirect– fstabNov 30, 2014 at 1: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.– CeladaNov 30, 2014 at 4:07
1 Answer
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>