0

I have the following Python code:

#!/usr/bin/env python
import sys
myargs = sys.argv[1]

mylist = ["foo bar qux", "uix nan col"]
for chunk in mylist:
    mems = chunk.split()
    mems.append(myargs)
    print mems

When executed the following python test.py param giving this results:

['foo', 'bar', 'qux', 'param1']
['uix', 'nan', 'col', 'param1']

What I want to do is to use PHP to call the above python script and parse the output. I have this in my php code (index.php):

<HTML>
<HEAD>
<TITLE>MYCODE</TITLE>
</HEAD>
<BODY>
<BR>


 <?php echo '<p>This is the output of my code:</p>'; ?>
<?php
 $vars = eval(`python /misc/path_to_mycode/test.py param1`);
 var_dump($vars)
?>

</BODY>
</HTML>

But it prints this instead over the web: enter image description here

1 Answer 1

1

Use exec() in php.Try like this

<?php echo '<p>This is the output of my code:</p>'; 
 exec('python /misc/path_to_mycode/test.py param1',$out);
 var_dump($out)
?>

The exec function just return the last line from the result of the command.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.