Solved

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

Posted on 2011-09-11
12
1,740 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
  • 6
  • 2
  • 2
  • +1
12 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
Sure,

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

0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
 
LVL 1

Author Comment

by:Scamquist
Comment Utility
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
Comment Utility
Copy CMD.EXE file from the Windows\System32\ folder to your PHP directory (c:\PHP\)
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:Scamquist
Comment Utility
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
Comment Utility
0
 
LVL 1

Author Comment

by:Scamquist
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now