How to Redirect the Output of an Application in Background to /Dev/Null

How to redirect the output of an application in background to /dev/null

You use:

yourcommand  > /dev/null 2>&1

If it should run in the Background add an &

yourcommand > /dev/null 2>&1 &

>/dev/null 2>&1 means redirect stdout to /dev/null AND stderr to the place where stdout points at that time

If you want stderr to occur on console and only stdout going to /dev/null you can use:

yourcommand 2>&1 > /dev/null

In this case stderr is redirected to stdout (e.g. your console) and afterwards the original stdout is redirected to /dev/null

If the program should not terminate you can use:

nohup yourcommand &

Without any parameter all output lands in nohup.out

Redirecting a Java background process output to /dev/null - is this a good idea?

Definitely send this info to a log file. Redirecting stdout/stderr to /dev/null means you're throwing away valuable info. Send the output to either one or two files. It's probably easier to redirect stderr to stdout so you can interleave the results. As to where you log this info, it's probably best to ask your system admins, since they will likely have views on where this sort of info should go (and you don't know yet how much info you've got coming out).

One particular scenario in which this is valuable is when the JVM itself crashes (as opposed to your application within the JVM). A crash report gets dumped out to stdout and if you're capturing stdout that's valuable if only to tell you why the JVM disappeared.

How can I redirect all output to /dev/null?

Redirection operators are evaluated left-to-right. You wrongly put 2>&1 first, which points 2 to the same place, as 1 currently is pointed to which is the local terminal screen, because you have not redirected 1 yet. You need to do either of the following:

2>/dev/null 1>/dev/null google-chrome &

Or

2>/dev/null 1>&2 google-chrome &

The placement of the redirect operators in relation to the command does not matter. You can put them before or after the command.

Bash: Silence a process put into background

One option is:

  1. Bringing the job to the foreground (see Job control).
  2. Redirecting ouput (see below).
  3. Sending to the backgrouond again.

How to redirect output of an already running process

https://superuser.com/questions/473240/redirect-stdout-while-a-process-is-running-what-is-that-process-sending-to-d

Redirect STDERR / STDOUT of a process AFTER it's been started, using command line?

https://etbe.coker.com.au/2008/02/27/redirecting-output-from-a-running-process/

In Linux how do you make a command run in the background without it outputting to the screen?

Try

arpspoof -t 10.1.1.1 10.1.1.2 2>/dev/null 1>/dev/null &

where:

arpspoof -t 10.1.1.1 10.1.1.2 is your command

2>/dev/null redirects standard error (STDERR) to the "bit bucket"

1>/dev/null redirects standard out (STDOUT) to the "bit bucket"

& sets the entire command line to run in the background

This line of code is more verbose and perhaps clearer to understand.

Running a process in the background with input/output redirection

Control operator

There are two uses of & here. One is as a so-called control operator. Every command is terminated by a control operator such as &, ; or <newline> . The difference between them is that ; and <newline> run the command in the foreground and & does it in the background.

setsid python script.py < /dev/zero & > log.txt &
setsid python script.py & < /dev/zero > log.txt

These two lines, therefore, actually execute two commands each. The first is equivalent to the two commands:

setsid python script.py < /dev/zero &
> log.txt &

And the second is equivalent to:

setsid python script.py &
< /dev/zero > log.txt

If you're wondering, yes, > log.txt and < /dev/zero > log.txt are both legal commands. Lacking a command name, they simply process the redirections: each one creates an empty file called log.txt.

Redirection

setsid python script.py < /dev/zero &> log.txt &

This version with &> is different from the one with & >. &> without a space is a special redirection operator in bash that redirects both stdout and stderr.

setsid python script.py < /dev/zero > log.txt &

This final version is similar to the previous one except it only redirects stdout to log.txt. stderr continues to go to the terminal.



Related Topics



Leave a reply



Submit