简体   繁体   中英

Windows PHP exec / shell_exec with phantomjs always returns null

I'm running PHP 5.4.9 on Windows server

I've tried running all script commands in PHP (exec, shell_exec, system, proc_open, passthru). All seem to return empty or null.

I've added phantomjs as a PATH variable.

And running phantomjs --version in command prompt, and it returns 1.8.2

Although when I try to run

$return = exec("phantomjs --version")

or

$return = shell_exec("phantomjs --version", $output)

$return is always null and $output is empty.

I made sure IUSR and IIS_IUSRS users have permission to run phantomjs.exe

Safe mode is disabled in php.ini

Also, I tried running exec('ls') && exec('ipconfig /all') , and those output the data I'm expecting.

I'm not sure what else to try.

我遇到了同样的问题。.问题是phantomjs需要所有对象的完整路径这是我想出的解决方案:

$getout = exec('D:\\xampp\\htdocs\\phantomjsdir\\phantomjs.exe D:\\xampp\\htdocs\\rasterisejsdir\\rasterize.js http://localhost/pagetobecaptured/test D:\\xampp\\htdocs\\outputfiledir\\test2.jpg "1800px*840px"',$o,$e);

You are pretty close to a solution. It's basically:

$stdout = shell_exec('time /T');
echo $stdout;

You need to make sure, that the Phantom binary is either on path or called with full-path.

For a full example executing PhantomJS, see the driver file of "jakoch/PHPUnit-headless" .

I keep getting a return value of NULL from proc_open with php 7.2, what could be the cause, on windows, the spawned process pid is valid though (the process is long running):

$descriptorspec = array(
    0 => array("pipe", "r"), // stdin for worker
    1 => array("pipe", "w"), // stdout for worker
    2 => array("pipe", "w"), // stderr for worker
);
$user->worker = proc_open('C:\wamp64\bin\php\php7.2.18\php watch.php', $descriptorspec, $user->pipes); 
if(is_resource($user->worker)) 
{
    $ppid = proc_get_status($user->worker)['pid'];
    echo "WORKER:".var_export($user->worker, true)." pid ".$ppid);
}

this is stored in a public member "worker" of an instance of a derived class "user"

should I try array('bypass_shell'=>true) );
perhaps as option to proc_open in order to avoid cmd shell, thank you for any clues

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM