Warning: exec(): Unable to fork error when calling batch file

I am trying to ececute a batch file from php.

When I open the page, I get the following error:

Warning: exec(): Unable to fork [UploadRecipeToMas.bat] in C:\Inetpub\wwwroot\CallFile.php on line 2

The PHP code is:


The UploadRecipeToMas.bat file has a single line

osql -E -d Iris -S Gamay-srv1 -Q "Exec MASExport ;

When I double click the batch file, the stored procedure is executed

I gave Read & Execute and Read permissions to Internet Guest Accout MyDomain\IUSR_Server1 in the following files


I am running php 5.3.7 and IIS 6.0, Allowing Anonymous Access on Server 2003

Any ideas.  You help will be appreciated.
Who is Participating?
derduffConnect With a Mentor Commented:
There is a typo in

cacls %COMPSEC%

It should read (switch P <=> S)

cacls %COMSPEC%

Please enter

echo %COMSPEC%


calcs %COMSPEC%

in the command prompt and post the result.

Other things:

Have you tried using the full path to the batch file in the exec() function?
Are you able to exec() standard system commands (e.g. echo)?

Ray PaseurCommented:
Can you please step back from the technical details here and just tell us in plain language what you are trying to do?  Once we understand that, we may be able to suggest a well-respected design pattern.  Thanks, ~Ray
ScamquistAuthor Commented:

I am trying to call a batch file from php using the exec() command.

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Ray PaseurCommented:
A batch file to do what?  A non-technical description would be best.  Catch fish?  Set a fire?  

Please go way up the chain and tell us from the 50,000-foot view, thanks!
ScamquistAuthor Commented:
The batch file is executing sql 2005 stored procedure.  The procedure is used refresh two tables from data extracted from a MAS90 business system.

Is there any other information that would help?

I have been pounding my head against this for a few days now.
Copy CMD.EXE file from the Windows\System32\ folder to your PHP directory (c:\PHP\)
Lukasz ChmielewskiCommented:
1. try following these instructions
2. try using shell_exec
ScamquistAuthor Commented:
Copied CMD.EXE to C:\PHP.  Same error message

Roads Roads.
from link, entered
at command prompt.  
Returned error:
No mapping between account names and security IDs was done

I also changed the code to:

Returned error:
Warning: shell_exec(): Unable to execute 'UploadRecipeToMas.bat' in C:\Inetpub\wwwroot\CallFile3.php on line 2

Lukasz ChmielewskiCommented:
ScamquistAuthor Commented:
KB 890737 has a fix, but it applys to XP.  I am running Server 2003 SP2.  

Searched for other No mapping between account names and security IDs was done but have not found anything relevant.

Forgot to mention, when I opened a command window and entered

cacls %COMPSEC%

received an error:
the system cannot find the file specified

cacks.exe does display the following:

C:\Documents and Settings\administrator.GAMAY>cacls.exe
Displays or modifies access control lists (ACLs) of files

CACLS filename [/T] [/M] [/S[:SDDL]] [/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.
   /M            Changes ACLs of volumes mounted to a directory
   /S            Displays the SDDL string for the DACL.
   /S:SDDL       Replaces the ACLs with those specified in the SDDL string
                 (not valid with /E, /G, /R, /P, or /D).
   /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.

   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.
ScamquistAuthor Commented:
It is working now.  I entered the full path to the batch file.

(fyi, I think you had a typo in calcs %COMSPEC%     should be cacls %COMSPEC%    is that right)

Results for command prompt:
C:\Documents and Settings\administrator.GAMAY>echo %COMSPEC%

C:\Documents and Settings\administrator.GAMAY>cacls %COMSPEC%
C:\WINDOWS\system32\cmd.exe BUILTIN\Administrators:F
                            NT AUTHORITY\ANONYMOUS LOGON:R
                            NT AUTHORITY\BATCH:R
                            NT AUTHORITY\INTERACTIVE:R
                            NT AUTHORITY\SERVICE:R
                            NT AUTHORITY\SYSTEM:F

I entered the folowing code:
echo exec('whoami');
Domain\iusr_servername was returned

Full path may have solved it.
ScamquistAuthor Commented:
Thank you so much.  I wish it could be 5000 points!  I have been trying to get this to work for days.

Thank you.

All Courses

From novice to tech pro — start learning today.