I am simply calling python script from my php program and I need to display the output return from python script to webpage. I am new to this, so I tried many ways to get the output return,
1.
$command = escapeshellcmd('python script.py "ab" "cd" ');
$output = shell_exec($command);
2.
$output = shell_exec('python script.py "ab" "cd" ');
print $output;
3.
$command = system('python script.py "ab" "cd" ',$output);
echo "output is ".$output;
echo "command is".$command;
4.
$command = passthru ('python script.py "ab" "cd" ');
$output = shell_exec($command);
echo $output;
5.
exec('python script.py "ab" "cd" ', $output, $return_var);
echo $output;
echo $return_var;
If time taken taken by python script is less, then I able to get the output return to my php program and able to display on my web page.
print "Hello"
print "world"
But when my python program is calling any background process, which taking more time and giving output after few seconds, then that parts are not returning to the php program.
print "Hello"
returned_value=subprocess.check_output('ssh -p 29418 xyz.com --format=JSON', shell=True)
print returned_value
I tried to include sleep in php program but it is not helping as output is already returned. Some posts suggested to use Ajax
Whether that is the only and correct way to solve this question?
Thanks in advance for your help or suggestion.