简体   繁体   中英

PHP execute shell command and return full output

I'm having trouble getting the full output from a shell command returned to a PHP script.

If i run this command in the terminal:

cd /home/moodledata; sh gam-create.sh "12345" "Test" "Mc Person"

Then I get the following as output in the terminal:

Creating account for 654321@ourdomain.ac.uk Error 409: Entity already exists. - duplicate

However, if I run that through a PHP script:

<?php
$u = "Test";
$s = "Mc Person";
$u = "654321";

exec("cd /home/moodledata; sh gam-create.sh \"$u\" \"$f\" \"$s\"", $retval);
var_dump($retval);

I only get the following for the returned output:

array(1){
  [0] => string(49) "Creating account for 654321@ourdomain.ac.uk"
}

I don't get the error message.

I've played around with using different functions, such as shell_exec() passthru() and system() but can't see to get this full output to be returned to the PHP script.

Could anyone advise as to where I'm going wrong?

Cheers.

Sorry, nevermind, I worked it out now. I needed to append 2>&1 to the command

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM