exec() problem - maybe IIS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
acid coder
Forum Newbie
Posts: 7
Joined: Fri Aug 15, 2008 6:59 am

exec() problem - maybe IIS

Post 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
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: exec() problem - maybe IIS

Post 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
acid coder
Forum Newbie
Posts: 7
Joined: Fri Aug 15, 2008 6:59 am

Re: exec() problem - maybe IIS

Post 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!! :banghead:
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: exec() problem - maybe IIS

Post 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
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: exec() problem - maybe IIS

Post 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...
acid coder
Forum Newbie
Posts: 7
Joined: Fri Aug 15, 2008 6:59 am

Re: exec() problem - maybe IIS

Post 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.
acid coder
Forum Newbie
Posts: 7
Joined: Fri Aug 15, 2008 6:59 am

Re: exec() problem - maybe IIS

Post 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!
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: exec() problem - maybe IIS

Post 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.
Post Reply