In the shell you can do redirection, >
<
, etc., but how about AFTER a program is started?
Here's how I came to ask this question, a program running in the background of my terminal keeps outputting annoying text. It's an important process so I have to open another shell to avoid the text. I'd like to be able to >/dev/null
or some other redirection so I can keep working in the same shell.
Short of closing and reopening your tty (i.e. logging off and back on, which may also terminate some of your background processes in the process) you only have one choice left:
e.g.:
You may also consider:
screen
; screen provides several virtual TTYs you can switch between without having to open new SSH/telnet/etc, sessionsnohup
; this allows you to close and reopen your session without losing any background processes in the... process.riffing off vladr's (and others') excellent research:
create the following two files in the same directory, something in your path, say $HOME/bin:
silence.gdb, containing (from vladr's answer):
and silence, containing:
Now, next time you forget to redirect firefox, for example, and your terminal starts getting cluttered with the inevitable "(firefox-bin:5117): Gdk-WARNING **: XID collision, trouble ahead" messages:
You could also redirect gdb's output to /dev/null if you don't want to see it.
Not a direct answer to your question, but it's a technique I've been finding useful over the last few days: Run the initial command using 'screen', and then detach.
https://www.isi.edu/~yuri/dupx/
this is bash script part based on previous answers, which redirect log file during execution of an open process, it is used as postscript in
logrotate
processThis will do:
It's not that clean (shows lines like:
write(#,<text you want to see>)
), but works!You might also dislike the fact that arguments are abbreviated. To control that use the
-s
parameter that sets the maximum length of strings displayed.It catches all streams, so you might want to filter that somehow:
shows only descriptor 1 calls.
2>&1
is to redirect STDERR to STDOUT, asstrace
writes to STDERR by default.