個人のUbuntuサーバーマシンに次のPHPコードがあります。
$cmd = 'su testuser'; $descriptorspec = 配列( array('パイプ', 'r'), array('パイプ', 'w'), array('パイプ', 'w') ); $パイプ = 配列(); $process = proc_open($cmd, $descriptorspec, $pipes); fwrite($pipes[0], 'パスワード\r'); fclose($パイプ[0]); $string = array(stream_get_contents($pipes[1]), stream_get_contents($pipes[2])); proc_close($プロセス); echo exec('whoami') . "\n"; print_r($string);
そして、私はPHPからこの応答を得ます:
www-データ 配列 ( [0] => [1] => su: 端末から実行する必要があります )
アクティブユーザーを変更したいのは明らかですが、phpからこれを行う方法はありますか?