你正在执行的是
echo 'hello' > /dev/pts/2 | /usr/bin/at 19:36
意义
echo 'hello' > /dev/pts/2
并将标准输出管道传输到,/usr/bin/at 19:36
但由于您已经将回声重定向到/dev/pts/2
,这将是空的。你可能打算做的是:
echo system("echo 'echo hello > /dev/pts/2' | /usr/bin/at 19:36");
您可能还想使用shell_exec
通过 shell 传递命令,或者proc_open
让您更好地控制正在执行的命令的 stdin/out/err。您的示例将对应于(改编自 php.net 文档的示例):
<?php
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a pipe that the child will write to
);
$process = proc_open('/usr/bin/at', $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], 'echo "hello" > /dev/pts/2');
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$return_value = proc_close($process);
echo "command returned $return_value. stdout: $stdout, stderr: $stderr\n";
} else {
echo "Process failed";
}
?>