Monday, 2 June 2014

How to execute python in php || How to use exec() command for calling python in php

Hello all,

I have came through an interesting thing,that is running an python program from PHP interface. Sounds cool right! I have faced some problems and finally get it done with simple example.Which i want to share with you all. This might be helpful for you .


 <?php  
 $pyscript = 'G:\wamp\www\ll\test.py';  
 $python = 'C:\\Python27\\python.exe';  
 $cmd="$pyscript $python";  
 exec("$cmd", $output);  
 print_r($output);  
 var_dump($output);  
 ?>  


You can easily run a python program now.I have done this in windows environment.If u doing in ubuntu,there is no need for path variables.If you find this useful like my blog subscribe me.Thank you.

No comments:

Post a Comment