Link to home
Start Free TrialLog in
Avatar of anneaquilino
anneaquilino

asked on

How to run a batch file from PHP...exec() and system() not working.

Hi,

I am trying to run a batch file from PHP.  It works fine when run manually but when I try to call it from within PHP it doesn't run.  I've tried with exec() and system() with no luck.  Here is my code:


system("\\qcwbfxd1\webdata\fxhome\fx\chartupdate\convertimage.bat", $output);

or

exec("\\qcwbfxd1\webdata\fxhome\fx\chartupdate\convertimage.bat", $output);

$output returns a 1 in both cases.

Any help would be greatly appreciated.

Thanks, Anne
ASKER CERTIFIED SOLUTION
Avatar of CtrlAltDl
CtrlAltDl
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Since the batch file needs access to the CMD you need to give it permissions to cmd.exe:

From a dos prompt:
C:\WINDOWS\system32>cacls cmd.exe /E /G ServerName\IUSR_ServerName:R

Here is how to use cacls:

CACLS filename [/T] [/E] [/C] [/G user:perm] [/R user [...]]
               [/P user:perm [...]] [/D user [...]]
   filename      Displays ACLs.
   /T            Changes ACLs of specified files in
                 the current directory and all subdirectories.
   /E            Edit ACL instead of replacing it.
   /C            Continue on access denied errors.
   /G user:perm  Grant specified user access rights.
                 Perm can be: R  Read
                              W  Write
                              C  Change (write)
                              F  Full control
   /R user       Revoke specified user's access rights (only valid with /E).
   /P user:perm  Replace specified user's access rights.
                 Perm can be: N  None
                              R  Read
                              W  Write
                              C  Change (write)
                              F  Full control
   /D user       Deny specified user access.
Wildcards can be used to specify more that one file in a command.
You can specify more than one user in a command.

Abbreviations:
   CI - Container Inherit.
        The ACE will be inherited by directories.
   OI - Object Inherit.
        The ACE will be inherited by files.
   IO - Inherit Only.
        The ACE does not apply to the current file/directory.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial