Solved

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

Posted on 2011-09-11
12
1,844 Views
Last Modified: 2012-06-21
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:

<?php
exec('UploadRecipeToMas.bat');
?>

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

C:\WINDOWS\system32\cmd.exe
C:\Inetpub\wwwroot\UploadRecipeToMas.bat

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

Any ideas.  You help will be appreciated.
0
Comment
Question by:Scamquist
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
  • +1
12 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36520287
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
0
 
LVL 1

Author Comment

by:Scamquist
ID: 36520293
Sure,

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

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36520386
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!
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 1

Author Comment

by:Scamquist
ID: 36520412
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.
0
 
LVL 2

Expert Comment

by:derduff
ID: 36523976
Copy CMD.EXE file from the Windows\System32\ folder to your PHP directory (c:\PHP\)
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 36524738
1. try following these instructions
http://www.iis-aid.com/articles/trouble_shooting/warning_exec_function_exec_unable_to_fork
2. try using shell_exec
0
 
LVL 1

Author Comment

by:Scamquist
ID: 36524982
Derduff.  
---------------------
Copied CMD.EXE to C:\PHP.  Same error message

Roads Roads.
---------------------
from link, entered
cacls %COMSPEC% /E /G %COMPUTERNAME%\IUSR_%COMPUTERNAME%:R
at command prompt.  
Returned error:
No mapping between account names and security IDs was done

I also changed the code to:
<?php
shell_exec('UploadRecipeToMas.bat');
?>

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

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 36525262
0
 
LVL 1

Author Comment

by:Scamquist
ID: 36525579
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.

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.
0
 
LVL 2

Accepted Solution

by:
derduff earned 500 total points
ID: 36527442
There is a typo in

cacls %COMPSEC%

It should read (switch P <=> S)

cacls %COMSPEC%

Please enter

echo %COMSPEC%

and

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)?

0
 
LVL 1

Author Comment

by:Scamquist
ID: 36529165
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:\WINDOWS\system32\cmd.exe

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
                            GAMAY\IIS_WPG:F
                            NT AUTHORITY\INTERACTIVE:R
                            GAMAY\IUSR_GAMAY-SRV1:F
                            NT AUTHORITY\SERVICE:R
                            NT AUTHORITY\SYSTEM:F
                            GAMAY\TelnetClients:R
                            BUILTIN\Users:R



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

Full path may have solved it.
0
 
LVL 1

Author Closing Comment

by:Scamquist
ID: 36529173
Thank you so much.  I wish it could be 5000 points!  I have been trying to get this to work for days.

Thank you.

Steve
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question