tags:

views:

30

answers:

1

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?

+3  A: 

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`
John Kugelman