Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么Linux命令dmidecode在exec中使用时不返回任何内容?_Php_Linux_Terminal_Debian_Exec - Fatal编程技术网

Php 为什么Linux命令dmidecode在exec中使用时不返回任何内容?

Php 为什么Linux命令dmidecode在exec中使用时不返回任何内容?,php,linux,terminal,debian,exec,Php,Linux,Terminal,Debian,Exec,如果在终端中运行命令“dmidecode-s处理器频率”,则显示信息:2000 MHz。 但当我运行PHP脚本时: exec("dmidecode -s processor-frequency", $output); print_r($output); 它什么也不返回 更新: 示例中的命令返回1行。在这种情况下,我们可以使用exec 是否可以使用此应用程序路径而不是dmidecode? 但是路径是什么?的$output只包含结果的最后一行: 命令结果的最后一行。如果您需要执行命令并将命令中的所

如果在终端中运行命令“dmidecode-s处理器频率”,则显示信息:2000 MHz。 但当我运行PHP脚本时:

exec("dmidecode -s processor-frequency", $output);
print_r($output);
它什么也不返回

更新:
示例中的命令返回1行。在这种情况下,我们可以使用exec
是否可以使用此应用程序路径而不是dmidecode? 但是路径是什么?

$output
只包含结果的最后一行:

命令结果的最后一行。如果您需要执行命令并将命令中的所有数据直接传回而不受任何干扰,请使用
passthru()
函数

如果要捕获完整输出,请使用或

passthru

$command = "dmidecode -s processor-frequency";
passthru($command, $output);
echo $output;
$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);
proc\u open

$command = "dmidecode -s processor-frequency";
passthru($command, $output);
echo $output;
$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);
$output
仅包含结果的最后一行:

命令结果的最后一行。如果您需要执行命令并将命令中的所有数据直接传回而不受任何干扰,请使用
passthru()
函数

如果要捕获完整输出,请使用或

passthru

$command = "dmidecode -s processor-frequency";
passthru($command, $output);
echo $output;
$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);
proc\u open

$command = "dmidecode -s processor-frequency";
passthru($command, $output);
echo $output;
$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);

@NazarVozniy,那么命令返回
error 127
string。如果这不是您所期望的,那么问题应该在命令本身。我刚刚演示了如何捕获
stdout
stderr
@NazarVozniy,然后命令返回
error 127
string。如果这不是您所期望的,那么问题应该在命令本身。我刚刚演示了如何捕获
stdout
stderr