You are not logged in.

#1 2014-07-17 18:27:07

ysetdng
Member
Registered: 2014-05-02
Posts: 42

[SOLVED] Can you do a permament stderr redirection to /dev/null?

Like, I'm not sure if I'm doing this right but I don't use an application launcher since I like how the fish shell does auto completion and remembers commands.  So for example I launch mupdf as

mupdf [some file] &

in fish, then launch cmus in the same shell and when mupdf puts some error, like that it can't find a certain string, the output disrupts my cmus interface.

I read somewhere that you can do

exec 2> /dev/null

but fish refuses to accept this and also I don't know if you can put this to .xinit or somewhere to make it permanent.

Also I could manually always do

mupdf [some file] 2> /dev/null &

but that seems clumsy.

Any recommendations?  Would creating an alias for any application with the '2> /dev/null' appended to the name be the appreciated way (still seems clumsy to me)?

Last edited by ysetdng (2014-07-17 21:03:44)

Offline

#2 2014-07-17 18:41:05

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED] Can you do a permament stderr redirection to /dev/null?

You can't do that with an alias, but a function in your shell rc file will do,

 mupdf() { command mupdf "$@" 2> /dev/null; }

This silver ladybug at line 28...

Offline

#3 2014-07-17 18:52:04

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,564
Website

Re: [SOLVED] Can you do a permament stderr redirection to /dev/null?

Or more generic:

back() { nohup $@ >/dev/null 2>&1 & }

This also redirects the stdout - if you don't want to see stderr output, I'm pretty sure you'd also not want stdout.  I've also added nohup, so the launched program doesn't get killed if the shell is exited.  I have this function in my bashrc, except I use setsid rather than nohup.

Redirecting all stderr from everything permanently would be a horrible idea.  What if makepkg or pacman failed for some reason - you'd have no idea why.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2014-07-17 19:59:15

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED] Can you do a permament stderr redirection to /dev/null?

Trilby wrote:

Or more generic:

back() { nohup $@ >/dev/null 2>&1 & }

<snip>
except I use setsid rather than nohup
<snip>

How can you call it "back"? Do you think people would have loved sudo so much if it had been called "notme"? Here, market this thing right:

hush () {
  setsid "$@" > /dev/null 2>&1
}

Seriously though, thank you for this Trilby.


This silver ladybug at line 28...

Offline

#5 2014-07-17 20:08:08

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,564
Website

Re: [SOLVED] Can you do a permament stderr redirection to /dev/null?

I thought about other names - "bg" was the first, but this is a bash builtin, so that'd be bad.  'hush' is much better for the present purposes, but I wrote the function primarily for "backgrounding" processes rather than just shutting them up.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2014-07-17 20:46:24

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED] Can you do a permament stderr redirection to /dev/null?

How about "scram"? Feels proper in either sense.

"Shut up and fuck off!"

Last edited by lolilolicon (2014-07-17 20:47:35)


This silver ladybug at line 28...

Offline

#7 2014-07-17 21:03:22

ysetdng
Member
Registered: 2014-05-02
Posts: 42

Re: [SOLVED] Can you do a permament stderr redirection to /dev/null?

Cool, thanks!  Fish does not want me to use variables as commands, so I used the first approach where I only define the function 'mupdf'.  I may switch to zsh soon but for now this is enough since I currently don't have this problem with other software (things like Firefox, where no arguments need to be specified, I launch in dmenu anyway).

Last edited by ysetdng (2014-07-17 21:04:27)

Offline

Board footer

Powered by FluxBB