Page 1 of 1
exec() problem - maybe IIS
Posted: Tue Sep 02, 2008 9:58 am
by acid coder
Hey all I have the following code;
Code: Select all
if(exec("C:\Flash.bat"))
{
echo("Working!");
}else {
echo("Not Working!");
}
It's running on php 5.2.3 and using IIS.
The code always says it's working, but the .bat is not running. I have checked the .bat file and it works fine at the command line. I have used this exact code on my WAMP box (php 5.0.3) and it works fine.
I have tried changing exec("C:\Flash.bat") to exec("cmd.exe /c C:\Flash.bat") as this has been suggested in the past when running on IIS, but it didn't make any difference.
Can anyone think of anything else? PHP.ini setting or IIS setting maybe? Or even another way of coding it?
Thanks
Re: exec() problem - maybe IIS
Posted: Tue Sep 02, 2008 11:12 am
by andyhoneycutt
acid coder wrote:
Can anyone think of anything else? PHP.ini setting or IIS setting maybe? Or even another way of coding it?
You may want to make sure that exec() isn't turned off in your php.ini by means of the "disable_functions" parameter.
Regardless, I think this page will help you find a solution to your problem:
Executing background processes from PHP on Windows
-Andy
Re: exec() problem - maybe IIS
Posted: Tue Sep 02, 2008 11:43 am
by acid coder
Thanks Andy. I have tried everything on that page and none of it worked. I guess it must be either a permissions / user problem or a problem with IIS. The pain of it is it dosen't return any errors, it just says it works!
It's really giving me a headache!!

Re: exec() problem - maybe IIS
Posted: Tue Sep 02, 2008 12:21 pm
by andyhoneycutt
Have you tried to print the output of your system call?
I would suggest something like this for troubleshooting purposes:
Code: Select all
$x = 0;
system("mySystemCommand",$x);
print_r($x);
-Andy
Re: exec() problem - maybe IIS
Posted: Tue Sep 02, 2008 12:59 pm
by Bill H
Does the user have "execute" permission in that directory where the bat file resides? If it only had "read" or "read/write" permission the the script cannot execute a file of any type, and I think system() would not return anerror under that circumstance.
I'm not real expert on servers, so I don't know for sure who has to have the permission. System, owner, user...
Re: exec() problem - maybe IIS
Posted: Wed Sep 03, 2008 5:06 am
by acid coder
Cheers for your help! I have echoed the command and it looks fine, i then ran that command from the command line in the same directory (that was echoed) and the .bat ran fine. IIS is using anonymous access and I have added the user id used for this to the administrator group. I have now added full control access rights for administrators to the entire C: drive and still no joy.
Looks like it's not going to work, which is a bummer, as being able to do this simple operation would have saved the company a lot of money.
If anyone can think of anything please let me know!
Thanks All.
Re: exec() problem - maybe IIS
Posted: Fri Sep 05, 2008 5:41 am
by acid coder
Have you tried to print the output of your system call?
I would suggest something like this for troubleshooting purposes:
Code: Select all
$x = 0;
system("C:\My.bat",$x);
print_r($x);
I have some spare time today and am looking at this again. I ran the above and it displays the command line followed by a 1. As this code on my WAMP display the command line and then a 0 I guess it is returning an error on the IIS server. Reading the manual it says the 1 indicates the command did not execute successfully, does anyone have any ideas how I can find out what this error is?
(Sorry I didn't read that post properly the first time, was a bit hot headed that day!)
Any help appreciated.
Thanks!
Re: exec() problem - maybe IIS
Posted: Fri Sep 05, 2008 9:44 am
by Bill H
Well, all it tells you is that system() ran but that the batch file did not. Since the batch file is not returning an error code, and presumably would not do so even if it did run, then system() can't tell you much other than that the called process did not run. It could still be a permissions problem, since command line and PHP are not the same user. PHP is usually user "99" on a shared Unix server, at least it is on mine, so you might see if that user has execute permission.