Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print python script output correctly in PHP

Tags:

python

php

i have a php file calls a script and prints the output like this


    $output=shell_exec('/usr/bin/python hello.py');
    echo $output;

it prints;


    b'total 16\ndrwx---r-x 2 oae users 4096 Jul 31 14:21 .\ndrwxr-x--x+ 9 oae root 4096 Jul 26 13:59 ..\n-rwx---r-x 1 oae users 90 Aug 3 11:22 hello.py\n-rwx---r-x 1 oae users 225 Aug 3 11:22 index.php\n'

but it should be like this;


    total 16K
    drwx---r-x  2 oae users 4.0K Jul 31 14:21 ./
    drwxr-x--x+ 9 oae root  4.0K Jul 26 13:59 ../
    -rwx---r-x  1 oae users   90 Aug  3 11:22 hello.py*
    -rwx---r-x  1 oae users  225 Aug  3 11:22 index.php*

\n characters shouldn't be shown.How can i solve this?

like image 698
Alperen Elhan Avatar asked Mar 02 '26 11:03

Alperen Elhan


1 Answers

this can be work

$output=shell_exec('/usr/bin/python hello.py');
echo "<pre>";
print_r($output);
echo "</pre>";
like image 74
umuthan Avatar answered Mar 05 '26 01:03

umuthan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!