简体   繁体   中英

exec() and passthru() php executing

I try to execute a python script with PHP But I got no results:I tried

$tmp = passthru("C:\\Python27\\python.exe C:\\Python27\\script.py C:\\Python27\\file.pdf",$output);
print($output)

The results :"1"

While

$tmp = exec("C:\\Python27\\python.exe C:\\Python27\\script.py C:\\Python27\\file.pdf",$output);

returns Array ( )

I'm excepted to return a string,any suggestions? I verified in my php.ini file

  safe_mode = Off

Thanks!!

The documentation of exec() says that the $output parameter is an array that will be filled in with each line. If you want to turn this into a single string, use:

$output_string = implode("\n", $output);

This should work for you:

ob_start();

passthru("C:\\Python27\\python.exe C:\\Python27\\script.py C:\\Python27\\file.pdf");

$filedata = ob_get_clean();

echo $filedata;

python buffers output by default. Set environment variable PYTHONUNBUFFERED to a nonempty string, or run python with -u.

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