-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpPythonPipe.php
More file actions
34 lines (25 loc) · 1.11 KB
/
phpPythonPipe.php
File metadata and controls
34 lines (25 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?PHP
// Inlining python from command line (Use an ANSI C-quoted string ($'...')),
// which allows using \n to represent newlines that are expanded to actual
// newlines before the string is passed to python:
// https://stackoverflow.com/questions/2043453/executing-multi-line-statements-in-the-one-line-command-line/2043633#2043633
// Viewing all defined variables
// https://stackoverflow.com/questions/633127/viewing-all-defined-variables
$path_to_python = "/home/filipi/anaconda3/bin/python";
$pythonCode = "import sys\n";
$pythonCode .= "print(\"Hello\")\n";
//$program = "'import sys\nfor r in range(10):\n\tprint(\"\$result[]=\\\"rob\\\";\")'";
//$program = "'import sys\nfor r in range(10):\n\tprint(\"\$result[]=\\\"rob\\\";\")'";
$command = $path_to_python . " -c '" . $pythonCode . "'";
$python_output = `$command`;
echo $python_output;
//eval($python_output);
//var_dump($result);
echo "==============================\n";
require_once("class.phpPythonPipe.php");
$python = new phpPythonPipe();
$python->kernelPath = $path_to_python;
$python->code = $pythonCode;
$python->exec();
$python->print();
?>