Running Python script in PHP: capture all outputs

前端 未结 1 1640
失恋的感觉
失恋的感觉 2021-01-13 04:43

I have a Python program that has multiple print statements in it. When I execute the program from PHP, the output displayed is just th

相关标签:
1条回答
  • 2021-01-13 05:21

    Try with shell_exec - Execute command via shell and return the complete output as a string

    escapeshellcmd() escapes any characters in a string that might be used to trick a shell command into executing arbitrary commands.

    Name your file like- python_script.py and follow the given script-

    $command = escapeshellcmd('python_script.py');
    $output = shell_exec($command);
    echo $output;
    

    Ref# running-a-python-script-from-php

    0 讨论(0)
提交回复
热议问题