dev/null and dev/null 2>&1?
Solution 1
I'm assuming you're looking for the difference between something like this:
$ php -q /http/get_pdf.php > /dev/null
and this:
$ php -q /http/get_pdf.php > /dev/null 2>&1
The first version redirects stdout
to /dev/null
, and the second redirects both stdout
and stderr
to /dev/null
.
Solution 2
When you have a command like:
COMMAND > /dev/null 2>&1
The "> /dev/null" part says to redirect all Standard Output from the command to the bit bucket. The "2>&1" part says redirect all Standard Error to Standard Out (which in turn gets redirect to /dev/null)
So essentially that will suppress all output.
Solution 3
You mean something like /command >/dev/null 2>&1
?
/command
: will be run>/dev/null
: redirect standard output to nothing (/dev/null
is a special null device, that means no output will be shown)2>&1
: redirect errors to stdout.
If you are running this as cron, stdout is often a mail (if errors occurs, mail to administrator)
Related videos on Youtube
neolix
Updated on September 17, 2022Comments
-
neolix almost 2 years
What dose mean dev/null and dev/null 2>&1 ? if i run php -q /http/get_pdf.php
sorry for my short question when we run this file from url it will create a .pdf file and mail, we are looking to send a mail using cron in that case we need to run one pdf report for one time.
suppose goto url https://example.com/get_pdf.php it will ask me mail id once we add mail id it will generate report what you ask for from drop down manu like what is sale for week? it will be mail on mail id, we don't want to from url we want happend from cron. Can same pls help me.
-
neolix almost 14 yearsyes i want to run as cron thanks for your quick reply how do run in cron can send me step pls. thanks in advance!!
-
neolix almost 14 yearsyes but same time i need to out to mail bcoz that get_pdf.php will create a .pdf file as report in one of the folder that i need to mail that pdf using cron
-
songei2f almost 14 yearsThis is basically universal syntax for stdout and stderr redirection. I have been quite surprised it works in not only every Unix/Linux variant I use (not so surprising), but Windows. That is universal, haha.
-
Philip almost 14 yearsWell technically the
2>&1
redirects stderr to stdout, which is redirected by the> /dev/null
part. But yes, they both end up going to the bit-bucket.