SOLUTION: My Python file was crashing with no output, I was able to diagnose this with a try/except that printed the error message. Oops!
I have a Windows 2012R2 IIS server set up to display websites that exist within a GitHub repo. After pulling the pages down from the repo I need to process them using a Python script, up to this point this happens twice a day as a scheduled task. The users would like to be able to run the batch file that updates/processes the files by clicking a button in the admin panel of the site. To do this I have created a PHP page that is supposed to execute the same batch file that the scheduled task uses. The problem I am running into is when the batch runs the git commands are executed just fine, but the Python script does not run.
I have already tried running the batch file using exec(), system(), and shell_exec(). I also tried running the batch file from a powershell script that runs the batch file. I'm guessing the PHP doesn't have the needed permissions to run Python files. Which is why I also tried passing Admin credentials to powershell through shell_exec. All of these have failed.
Here is watch the batch file looks like
cd C:\inetpub\wwwroot
git fetch --all
git reset --hard master
git pull https://username:password@github.com/user/repo_name
cd C:\inetpub
C:\Python37\python C:\inetpub\api_replace.py
And this is what I currently have in the PHP file.
<?php
session_start();
if(!isset($_SESSION["admin"]) || $_SESSION["admin"] !== true){
header("location: login.php");
exit;
}
$shellout = shell_exec('powershell C:\inetpub\refresh_pages.bat server_name\Administrator password');
echo $shellout
?>
I have also tried running the Python file directly through exec(), system(), and shell_exec().
The results of the git pull show up on the page, but none of the print statements from the Python file do. The necessary file processing also does not occur.