0

Looking at another post, I saw one of the ways to get the live output of a Python script executed in PHP was to use popen().

while (@ ob_end_flush()); // end all output buffers if any

                    $proc = popen('python -u test.py', 'r');
                    echo '<pre>';
                    while (!feof($proc))
                        {
                            echo fread($proc, 4096);


                        }
                    echo '</pre>';
            }

I want to know how I can use this popen() function and also pass in variables from PHP like you can do when using the exec() function like:

exec("python test.py $var1")

When I do:

$test = "hi";
popen('python -u test.py $test', 'r');

It gets passed as $test not "hi" but I want "hi".

0 Answers0