Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I know that in order to suppress the output of a program I can redirect it to /dev/null, for example to hide all error and warning messages from chromium I can start the program like this

chromium-browser 2> /dev/null &

However, if I happen to forget about the error messages and type

chromium-browser &

(which is quite annoying when they appear in the middle of a command) I don't know what to do except for stopping the application and starting it again properly.

Can I somehow redirect error output without restarting the application?

share|improve this question

3 Answers 3

up vote 7 down vote accepted

You can also launch the browser with nohup and then close the terminal window with the following:

nohup chromium-browser &

This way, the browser will launch and detach from the console, that can then be closed quietly.

share|improve this answer
2  
that is acceptable, except for the fact that I'll have to remember to type nohup –  phunehehe Sep 3 '10 at 14:07
5  
@phu On zsh at least you can put setopt nohup in your .zshrc and it will nohup everything you run; I'm not sure about other shells –  Michael Mrozek Sep 3 '10 at 14:27
    
yes, great, I like it this way! –  phunehehe Sep 3 '10 at 14:41
2  
Or you can create an alias... alias chromium = nohup chromium –  pablox Oct 17 '12 at 21:04

This was answered here : here by vladr. The answer is (quoting) :

  • attach to the process in question using gdb, and run:
  • p dup2(open("/dev/null", 0), 1) (for stdout redirection)
  • p dup2(open("/dev/null", 0), 2) (for stderr redirection)
  • detach
  • quit

I tried it on the following script :

[edition after first comment :]

sleep 10 # so I can have the time to attach to the process
if [ "$sonorfather" == "father" ] # avoid infinite recursion 
then 
   sonorfather=son ./test & 
fi 

while true 
do 
   echo "stdout $sonorfather" 
   echo "stderr $sonorfather" >&2 
   sleep 1 
done 

I disabled the stderr output before the son process was created, here is the output :

stdout father 
stdout son 
stdout father 
stdout son 
[and so on...]. 

I hope this answer your question : the son process stderr was redirected too.

share|improve this answer
3  
that was very good, but then I may have problems with chromium, as it spawns a new process for each browser tab, anyway to resolve? –  phunehehe Sep 3 '10 at 9:02
    
Edited my post to answer you. –  Mike Perdide Sep 3 '10 at 9:49
    
Look like I'll need to redirect the output before the child processes are created? Thanks for the knowledge, but regarding the complexity I'd just go with nohup :) –  phunehehe Sep 4 '10 at 10:23

You could also setup an alias for chromium-browser to instead run chromium-browser 2> /dev/null

e.g. if you are using bash, edit /home/username/.bashrc and add line:

chromium-browser='chromium-browser 2> /dev/null'

or better yet

chrome='chromium-browser 2> /dev/null'

and save some keystrokes.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.