0

I have a console that is printing to stdout.

How do i get access to the command prompt and silence the output to stdout ?

Thanks .

Sunil D.
  • 17,983
  • 6
  • 53
  • 65

2 Answers2

0

If you don't want to see console output, don't log in to a console. If you are getting log messages written to a device that is not supposed to be a console, then your system is set up wrong. You need to change the kernel command line at boot which can set the console device.

Most likely you have a system with no GUI which is logging to the main display as its console. In that case you can change the message severity in /etc/rsyslog.conf from kern.* (the default) to kern.err. You might also consider fixing the broken program that is logging so many messages.

stark
  • 12,615
  • 3
  • 33
  • 50
  • I am talking from the perspective of a developer. Let say you are compiling a large application and it going to take 1 hour.Meantime you want to do some other work ..... but you do not want to open another console.... how do you quiten the output to stdout. –  Aug 07 '12 at 13:24
  • 1
    @user780803 - Use [GNU Screen](http://www.gnu.org/software/screen/) or [tmux](http://tmux.sourceforge.net/). – ghoti Aug 07 '12 at 15:55
0

You have a couple of alternatives:

  • Use your shell redirection and process control operators to send both the standard output and standard error of a command to a file, while also launching it in the background:

    For example in bash:

    make all 1>make.log 2>&1 &
    

    Even better you can use a separate file for each stream:

    make all 1>make.out 2>make.err &
    

    The command is launched in the background and the shell will let you know when it is finished. In the mean time you can use a text viewer or even just tail on the output files to see what is going on.

    If error messages are rare and you want to see them immediately, you could only redirect the standard output:

    make all 1>make.log &
    

    If you do not care about the console messages at all, just send them to /dev/null:

    make all 1>/dev/null &
    
  • If your concern about new consoles is the login procedure, you can use a tool such as GNU screen or tmux to create additional console windows within your current session.

  • If you want to gain access to the console where a process has already been started, you need first to stop it with the appropriate keyboard shortcut, then let it continue in the background. For example in Linux/bash with the Ctrl+Z shortcut:

    $ make all
    1/10
    2/10
    ^Z
    [1]+  Stopped                 make all
    $ bg
    [1]+ make all &
    3/10
    $ 4/10
    5/10
    6/10
    7/10
    8/10
    9/10
    10/10
    
    [1]+  Done                    make all
    $
    

    Unfortunately, there is no easy way to redirect/quiet the output of a process that is already running - the messages will still be flooding the console.

    Of course if you only need short-term access to the console (e.g. to check an output file), you can just not restart the process until after you are done:

    $ make all
    1/10
    2/10
    ^Z
    [1]+  Stopped                 make all
    $ ls
    1  2  Makefile
    $ fg
    make all
    3/10
    4/10
    5/10
    6/10
    7/10
    8/10
    9/10
    10/10
    $ 
    

    For more information on the bg and fg job control builtin commands of bash, have a look here.

Community
  • 1
  • 1
thkala
  • 84,049
  • 23
  • 157
  • 201
  • Thank you I was referring to your third scenario. I thought it might be possible. –  Aug 08 '12 at 16:13
  • @user780803: it seems that it *is* possible - as long as you do not mind your application being poked at with `gdb`. I think I would exhaust all other alternatives first, including interrupting the application, before going for the equivalent of performing brain surgery while blind-folded and riding on a horse... – thkala Aug 08 '12 at 17:10