[英]Doubts about popen
Is there any way to make popen supports operators like &, |有没有办法让 popen 支持像 &, | 这样的运算符etc?
ETC?
Example:例子:
$cmd = "/bin/sh -c" . " \"" . "whoami && uname" ."\"";
$han = popen($cmd, 'r');
echo(fread($han, 2096));
pclose($han);
Just the first command ( whoami ) gets executed rather than both只执行第一个命令 ( whoami ) 而不是两个
I know there are other functions, but I'm talking just about popen我知道还有其他功能,但我只是在谈论 popen
Use proc_open()
with your command to ensure &&
will work:在您的命令中使用
proc_open()
以确保&&
将起作用:
proc_open()
is similar topopen()
but provides a much greater degree of control over the program execution.proc_open()
与popen()
类似,但对程序执行提供了更大程度的控制。
<?php
$cmd = "/bin/sh -c" . " \"" . "whoami && uname" ."\"";
$han = proc_open($cmd, [ 0 => [ "pipe", "w" ]], $pipes);
echo stream_get_contents($pipes[0]);
proc_close($han);
Output of above:以上Output:
runner
Linux
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.