I have a Python file that calls an API and gets some information, which I then need to use in a PHP file. But when running PHP, I get the error "'1' is not recognized as an internal or external command, operable program or batch file." Is this related to my use of sys.argv in the Python file? Specifically:
id_num = sys.argv[1]
The PHP code I am testing is as follows:
<?php function getData($var_one) { $cd_command = 'cd Location'; $command = 'python getData.py ' . $var_one; print($command); $output = shell_exec($cd_command && $command); return $output; } $test_string = getData("CRT67547"); print($test_string); ?>
Print it out to make sure there is no problem with the command and the printout looks fine.
Print output such as: python getData.py CRT67547
Edit: Re-read the question, revised for clarity
You may need to modify the
shell_exec
parameters in your PHP. In PHP,&&
is aAND
logical operator, but I'm assuming you want it to be executed in the shell along with your two commands, like this:Or, to make your overall code cleaner:
Your shell should then run
cd Location && python getData.py CRT67547
.Depending on the location you set, you can even do this:
You can simplify this to: