I've read a lot of answers on here regarding this but I still haven't been able to figure it out. I have some PHP code that is trying to execute a Python script while the PHP also passes the Python some arguments, and then I want the Python to do something and return a value to the PHP.
I've tried it this way:
$url = "URL given";
$retailer = "other string";
$price = system("/usr/local/bin/python3 /full/path/script.py '" . $url . "' '" . $retailer . "'", $retval);
sleep(5);
print "Price: " . $price;
With the Python code (where the function being called prints the value):
def main():
getPrice(sys.argv[1], sys.argv[2])
main()
And the $price variable doesn't return anything even though if I run the command thats inside system() in Terminal it prints the value out fine.
I've also tried:
exec("/usr/local/bin/python3 /full/path/script.py", $output, $ret_code);
sleep(5);
print "Price: " . $output[0];
But in this case I've tried it the way above where the Python simply prints "hi" instead of passing the arguments through and I still get nothing, as well as trying it the way with passing the args in from earlier.
I can't tell if maybe the Python isn't being called, or perhaps it is and it returns nothing for some unknown reason but if anyone may know the issue here I would love to hear your thoughts