Executing a BAT file from PHP using exec()
Posted: Sun Aug 01, 2010 6:26 pm
Hello everyone,
I'm tearing out my hair on this one. I've looked all over the internet and I have no idea why my code isn't working. What I'm trying to do is run a batch file (.bat) from within PHP. I have PHP 5.2.14 running on IIS on my Windows 7 machine. One of the examples I looked on online that's used to check if exec is working had this code:
When I run that code locally it prints out my directory structure in my wamp folder (I named it wamp even though I'm running IIS since I'm used to looking in the wamp folder for localhost
). So it doesn't seem like exec is disabled. Anyway, when I try to run the following code:
it just hangs there as if it's trying to load something. That batch file is located in the same directory as the PHP code that's trying to run it and definitely works because I can just click on it and it opens the calculator.
I've tried this using other functions like system(), popen(), and even tried my hand at the Windows Shell with similar results. I'm sure I'm just missing a small something. Anyone have any idea?
I'm tearing out my hair on this one. I've looked all over the internet and I have no idea why my code isn't working. What I'm trying to do is run a batch file (.bat) from within PHP. I have PHP 5.2.14 running on IIS on my Windows 7 machine. One of the examples I looked on online that's used to check if exec is working had this code:
Code: Select all
exec('dir', $response);
foreach($response as $line) {
echo $line . "<br>";
}
Code: Select all
exec("cmd.exe /c notathome.bat");
I've tried this using other functions like system(), popen(), and even tried my hand at the Windows Shell with similar results. I'm sure I'm just missing a small something. Anyone have any idea?