Skip to content

Instantly share code, notes, and snippets.

@anmolgkv
Last active September 11, 2016 04:37
Show Gist options
  • Save anmolgkv/9b1660cce801dfecc26f77adf48b8e95 to your computer and use it in GitHub Desktop.
Save anmolgkv/9b1660cce801dfecc26f77adf48b8e95 to your computer and use it in GitHub Desktop.
<?php
$start_word = 'hello';
$end_word = 'world';
echo "Start word: ". $start_word . "<br />";
echo "End word: ". $end_word . "<br />";
echo "Running the test.py...";
echo "</br>";
$output = exec("python test.py ".$start_word." ".$end_word);
echo 'output from python script: ';
var_dump( json_decode($output, true));
?>
#!/usr/bin/env python
import sys, json
print('Number of arguments: ')
print(len(sys.argv))
print('arguments.')
print('Argument List:')
print(str(sys.argv))
result = {'status' : 'Yes!'}
print(json.dumps(result))
@anmolgkv
Copy link
Author

anmolgkv commented Sep 11, 2016

Save these files in a folder.
then go to the folder from CMD and type : php -S localhost:8001
Now in the browser open : http://localhost:8001
Also make sure that both python and php are set in the environment variable.
Leave comment if you still need any clarification.
You shoud see:
Start word: hello
End word: world
Running the test.py...
output from python script: array(1) { ["status"]=> string(4) "Yes!" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment