简体   繁体   中英

Trying to run python script in PHP

I'm trying to run a Python script inside a perl script with the following command:

system("python3 script.py -d http:\/\/site.com --no-interaction");

qx/python3 script.py -d http:\/\/site.com --no-interaction/;

On the operating system's command line, the Python script executes, but when I make a call from a PHP application, the perl work, but the python script don't work.

Do you get any error message from Perl side? Likely where your PHP/Perl script runs from isn't the same location as where script.py is at. Try by using full path to Python script. Also double check that python3 is in your $PATH.

For example: -> cat /home/me/python/script.py

print("This line will be printed.")

-> cat /home/me/perl/pytest.pl

#!/bin/env perl
print "From perl:\n";
system ("python3 /home/me/python/script.py");
cd /home/me/perl/
ksh
whence python3
"/usr/bin"
pytest.pl
"From perl:
 This line will be printed."

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