1

I have this PHP code:

ini_set('display_errors', 1);
ob_start();
passthru('/usr/bin/python3 /home/domains/mydomain.pl/public_html/a.py /home/domains/mydomain.pl/public_html/code2.txt');
$output = ob_get_clean(); 
echo $output;


$message = exec("/usr/bin/python3 /home/domains/mydomain.pl/public_html/a.py /home/domains/mydomain.pl/public_html/code2.txt");
print_r($message);

$command = shell_exec('python3 /home/domains/mydomain.pl/public_html/a.py /home/domains/mydomain.pl/public_html/code2.txt');
echo $command;

$output=shell_exec('python3 /home/domains/mydomain.pl/public_html/a.py /home/domains/mydomain.pl/public_html/code2.txt');
echo "<pre>$output</pre>";


$command = escapeshellcmd('python3 /home/domains/mydomain.pl/public_html/a.py /home/domains/mydomain.pl/public_html/code2.txt');
$output = shell_exec($command);
echo $output;

exec('sudo -u www-data python3 /home/domains/mydomain.pl/public_html/a.py /home/domains/mydomain.pl/public_html/code2.txt');

system("cd /usr/lib/cgi-bin && sudo python3 /home/domains/mydomain.pl/public_html/a.py /home/domains/mydomain.pl/public_html/code2.txt");

I would like PHP to: 1. launched the a.py script 2. returned the result which the console will display from a.py and display it in the web browser.

At the moment, nothing is showing up. I do not have any error message or warning.

Does anyone know what is wrong in the above code?

My server allows running scripts with the console

  • Hi again =) call `error_reporting(E_ALL);` after `ini_set` to be sure that you display all types of errors, especially the fatal ones, also don't use it (i.e. `ini_set` and `error_reporting`) in production environment, should only be used in your development machine. Since it will show errors to your users which is not professional plus it is considered a security flaw. – Ermac Nov 05 '18 at 00:00
  • Thank you for your response. I;m adding error_reporting (E_ALL); but it's nothing gave. I not see any messages from the console or any errors –  Nov 05 '18 at 00:16
  • Got it you probably have an error thrown by the command, and in order to show this error, you need to append this string `'2>&1'` at the end of the command you pass to your functions (e.g. `passthru`). See this ref: [PHP exec() not returning error message in output](https://stackoverflow.com/questions/3863699/php-exec-not-returning-error-message-in-output). – Ermac Nov 05 '18 at 00:41

0 Answers0