Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

replaced http://us3.php.net with https://www.php.net
Source Link

Try this:

<?php
$ret = exec("su -c /path/to/command -s /bin/bash -l otheruser", $out, $err);
var_dump($ret);
var_dump($out);
var_dump($err);
?>

More Info: http://us3.php.net/manual/en/function.exec.php https://www.php.net/manual/en/function.exec.php

Also, if you are expecting the exec command to ask you for the password for the other user (as it did in the linux command line) - it won't work, exec command isn't interactive. You'll need to pass the password on the command, inline.

Try this:

<?php
$ret = exec("su -c /path/to/command -s /bin/bash -l otheruser", $out, $err);
var_dump($ret);
var_dump($out);
var_dump($err);
?>

More Info: http://us3.php.net/manual/en/function.exec.php

Also, if you are expecting the exec command to ask you for the password for the other user (as it did in the linux command line) - it won't work, exec command isn't interactive. You'll need to pass the password on the command, inline.

Try this:

<?php
$ret = exec("su -c /path/to/command -s /bin/bash -l otheruser", $out, $err);
var_dump($ret);
var_dump($out);
var_dump($err);
?>

More Info: https://www.php.net/manual/en/function.exec.php

Also, if you are expecting the exec command to ask you for the password for the other user (as it did in the linux command line) - it won't work, exec command isn't interactive. You'll need to pass the password on the command, inline.

Source Link
Latheesan
  • 24.1k
  • 34
  • 113
  • 212

Try this:

<?php
$ret = exec("su -c /path/to/command -s /bin/bash -l otheruser", $out, $err);
var_dump($ret);
var_dump($out);
var_dump($err);
?>

More Info: http://us3.php.net/manual/en/function.exec.php

Also, if you are expecting the exec command to ask you for the password for the other user (as it did in the linux command line) - it won't work, exec command isn't interactive. You'll need to pass the password on the command, inline.

lang-php

AltStyle によって変換されたページ (->オリジナル) /