Reputation: 47
I have a python script that I want to execute from my codeigniter controller. I found a similar question but wasn't quite able to see the out put (Executing a Python file from Codeigniter)
Is there a way that I can run a python script from my CI appliation and get the output into a variable or something like that ?
Upvotes: 0
Views: 1616
Reputation: 326
You can execute a python script from php for example with the passthru function.
<?php
ob_start();
passthru('/full/path/to/python /full/path/to/test.py arg1 arg2');
$output = ob_get_clean();
echo $output;
?>
Or with the "system" function.
<?php
system('full/path/to/python /full/path/to/test.py', $return_value);
echo $return_value;
?>
But your python script should return something if you want to "see" someting.
import sys
#calculate stuff
sys.stdout.write('Bugs: 5 |Other: 10\n')
sys.stdout.flush()
sys.exit(0)
Upvotes: 1