I would like to run and store the value returned from a python script, in response to certain admin actions.
I've tried a bunch of suggested solutions but the only method that has worked for me is:
$python_script_path = get_template_directory() . '/hello.py';
$python_command = 'C:\Users\fluxian\AppData\Local\Microsoft\WindowsApps\python.exe ' . escapeshellarg($python_script_path);
ob_start();
passthru($python_command . ' dog');
$output = ob_get_contents();
ob_end_clean();
echo $output; // Hello dog
Which seems dirty, but if it works it works. I don't want to hard-code the location to a python install though. Is there a way to figure out where python is actually installed dynamically, instead of relying on hard-coding its location?
Whenever I run shell_exec or exec I get an error saying that python is not a recognised command. I assume the shell php is calling is not the cmd that Windows is exposing? Fixing that seems like a neater solution, if anyone knows how.