exec
さん$output
結果から最後の行だけが含まれています
コマンドの結果から、最後の行を。コマンドを実行し、コマンドからのすべてのデータを干渉なく直接戻す必要がある場合は、passthru()
関数を使用します。
フル出力をキャプチャする場合は、passthru
またはproc_open
を使用します。
passthru
$command = "dmidecode -s processor-frequency";
passthru($command, $output);
echo $output;
proc_open
$command = "dmidecode -s processor-frequency";
$desc = [ 1 => ['pipe', 'w'], 2 => ['pipe', 'w'] ];
$proc = proc_open($command, $desc, $pipes);
if (!is_resource($proc)) {
fprintf(STDERR, "command failed: $command\n");
exit(1);
}
if ($output = stream_get_contents($pipes[1])) {
fprintf(STDOUT, "STDOUT: %s\n", $output);
}
if ($error = stream_get_contents($pipes[2])) {
fprintf(STDERR, "STDERR: %s\n", $error);
}
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($proc);
まず例エラー127 –
@NazarVozniy、ウェル、コマンドリターン 'エラー127'文字列を返します。それがあなたが期待していたことでないなら、問題はコマンドそのものにあるべきです。私はちょうど 'stdout'と' stderr'をキャプチャする方法を示しました。 –