Executing command line from PHP

Use shell_exec() or exec(). shell_exec() is typically more useful, because it returns all of the output, whereas exec() only retuns a single line.

Check shell_exec() exists

You can find its been disabled in php.ini for instance.

  if(!function_exists('shell_exec'))
    echo('shell_exec() is not available. Please check your PHP configuration.');

Running a script with shell_exec()

  exec("/usr/bin/python3 $PathToScript $ProcessArguments" . " 2>&1", $Output, $Status);    //The  " 2>&1" part captures any error messages and puts them in the $Output array as well
  if ($Status === 0)
  {
    //----- SUCCESS -----
    echo "Output from Python script:<br>";
    foreach ($Output as $Line)
    {
      echo($Line . "<br>);

    }
  }
    //----- AN ERROR OCCURED -----
    echo "Error executing script ($Status).<br>";
    foreach ($Output as $Line)
    {
      echo($Line . "<br>);

    }
  }