Web Development Blog

24K Design Studio :: Blog :: How to get error channel(stderr) using shell_exec in PHP?
Author:
Password:
How to get error channel(stderr) using shell_exec in PHP?
00:17, 01 Dec, 2010
by David

I didn't find obvious function that can return the results in stderr. So shell_exec is a general solution.
It's not some special function, but just something standard in shell. The answer is "2>&1". It means redirect message in stderr into stdout.
For example:

shell_exec("dir")
will return the file list normally.

shell_exec("dirrrr")
will return null since all messages are in stderr and nothing in stdout.

shell_exec("dirrrr 2>&1")
will return the error message.

shell_exec("dir 2>&1")
will return the file list normally.

Tags: PHP Linux
Reply:
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2 =

Reply
#1
Deniz
11:14, 07 Jul, 2014
 
Cool tip. Thanks,.

Deniz Gezmis
Reply
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2 =

Reply
#1
psuupssf
05:03, 25 Nov, 2015
 
1
Reply
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2 =

Reply
#2
rtyrtytrytrytry
18:50, 12 Nov, 2016
 
ghfghfghfgh
Reply
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2 =

Reply
#2
rtyrtytrytrytry
18:50, 12 Nov, 2016
 
yhtrytryrty
Reply
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2 =

Reply
#3
rtyrtytrytrytry
18:50, 12 Nov, 2016
 
ghhjfjfghjfgjfg
Reply
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2 =

Reply
#4
rtyrtytrytrytry
18:50, 12 Nov, 2016
 
ghh
Reply
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2 =

Reply
View the latest 5 entries.