2

I start a gui app from a konsole window and it writes out totally useless information. I do not need that. Is there a way to stop this, once and for all? I tried disown, doesn't help. I guess 2>&1 >/dev/null might help but that's rather tedious!

OK, let's get creative. One half of the answer is to use preexec (I use zsh but the net is full of bash preexec tricks) and use ldd to detect libX11 (and what else?). Then https://stackoverflow.com/a/9188571/308851 shows how to create redirects to /dev/null. How can we expand this solution to work with programs having a shell script wrapper?

1

2 Answers 2

3

I know it's tedious but unless your app as a option to be executed in silence then I would go with

./app > /dev/null 2>&1

If you don't want to be always writing this that you can create your own alias in your shell profile.

.bashrc - for bash

you will need to create and alias:

alias app="/usr/local/bin/app > /dev/null 2>&1"

after updating your .bash_profile just relog or source ~/.bash_profile and just call the app.

EDIT: Correcting as per Michael comment, indeed the 2>&1 comes after the /dev/null. wonder if this is shell related.

5
  • This. But shouldn't it be >/dev/null 2>&1 (first redirect stdout, then redirect stderr to stdout)?
    – user
    Dec 21, 2012 at 9:40
  • To be honest, never tried like you have. I always redirect the stderr to stdout first and then redirect to where I want it to be So I always get the 2>&1 > <final_destination>
    – BitsOfNix
    Dec 21, 2012 at 9:45
  • Maybe it works "as intended" these days. I do recall that this was an issue to be considered some time ago, at least. But then again, I might be mistaken about that.
    – user
    Dec 21, 2012 at 9:46
  • 1
    Don't put aliases in ~/.bash_profile, put them in ~/.bashrc and source ~/.bashrc from ~/.bash_profile, otherwise you will lose the aliases in non-login shells.
    – Chris Down
    Dec 21, 2012 at 10:11
  • "I always redirect the stderr to stdout first and then redirect to where I want it to be." - that's not supposed to work: 2>&1 redirects stderr to the target of stdout right then, it doesn't tie them together. So if you do 'foo 2>&1 >somefile | bar', stdout should be piped to the next command.
    – FLHerne
    Mar 16, 2016 at 9:59
0

In zsh you can use &! -- that is,

gui-app --args --args &!
1
  • Just adding &! didn't work for me.
    – chx
    Jan 31, 2013 at 8:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .