I've got some code that I wrote that uses a combination of bash and PHP command line scripting. The script is ran as root and then uses su
to become various uses. I start a session like this:
$result = `su开发者_运维问答 SomeUser ./dothis.php`
Here ./dothis.php
is a script that may generate some output being stored in $result
, but the problem is that there is usually output that doesn't get caught and makes it hard for me to read my script output.
How can I make sure that the output is being captured within this su
stacking?
Use 2>&1
to redirect stderr to stdout. Backticks only capture output to stdout and will miss output to stderr.
$result = `su SomeUser ./dothis.php 2>&1`
精彩评论