Jump to content

Archived

This topic is now archived and is closed to further replies.

NEX2NUN

Unable to run batch from PHP

Recommended Posts

I'm stuck and I need some help!

I am attempting to execute a batch file from within PHP.
The batch file runs a DOS command to open and print (to a physical printer) a PDF document.

I have a tried a number of different options, but nothing prints out. I was getting a number of syntax errors, however, I then had to enable the Advanced Security functions and give the local user full access right to cmd.exe. Also I have enabled IIS to interact with the desktop. I'm getting no syntax errors now but I am also not getting my print out. I could list ALL of the code I have attempted but still I have gotten nothing. Here's on I tried.

[code]
<?php
exec('test.bat');
?>
[/code]

Any ideas?

[list]
[*]Windows XP
[*]IIS 5
[*]PHP 5
[/list]

-NEX

Share this post


Link to post
Share on other sites
exec should be running it, just make sure it's not user based.  I don't understand why it's not, is the script with exec on the exact same directory as the program.  If not you have to tell it where to find it at.

Share this post


Link to post
Share on other sites
Yeah I'm kind of stumped too. I'm not sure what I am missing. Could it be something disabled with PHP? IIS? I've Googled just about everything I can think of.

Yes the batch file and the PHP exec() function are all in the same directory.

The batch file contains the following:

[code]c:\reader\acrord32.exe /t c:\test.pdf[/code]

This calls Acrobat Reader executable and then prints the test.pdf document. The batch file works great when ran but not from PHP.

*shrugs*

Share this post


Link to post
Share on other sites
http://drupal.org/node/14002

http://us3.php.net/manual/en/ref.exec.php
read the user comments there, it has some stuff about windows.

http://bugs.php.net/search.php?cmd=display&search_for=exec%28%29
this will definitely probably help some go over those too and see if you find anything.

Share this post


Link to post
Share on other sites
Is the webserver a windows box? Remember PHP runs on the server, so if you are not running on a windows box, this won't work. Even if it is a windows box, BAT file reside on that box?

Ken

Share this post


Link to post
Share on other sites
@ken

Yes the web server is a Windows box, (XP Pro, SP2). The batch file is on the same box yes and in the same directory as the php script. PHP is running, I am able to create "Hello World" and see phpinfo(). I just can't get this function to work and it's the one function this system requires.

@businessman332211
I read a user comment that gave this as a suggestion for Windows

[code]
exec('c:\\WINNT\\system32\\cmd.exe /c START c:\\test.bat');
[/code]

Now I'm am wondering if PHP is waiting for some process to complete, because the above seems to be doing something, the page is still "opening page". One user commented using a delphi script but I am lost with that.

Here's their snippet

[code]
Delphi-snippet:
WinExec(PChar(<CMD>),SW_SHOW); // replace <CMD> with the program path.
[/code]

Share this post


Link to post
Share on other sites
check the bugs as well, there are a few bugs with windows, related to exec, make sure it's not that, I wish I could help but this is getting too deep, I have never used exec, or system, maybe system has some functionality you can use.  fopen opens files, but I don't know about applications.

Share this post


Link to post
Share on other sites
@businessman33221

I really appreciate the help! I'm thinking it will be something that I just didn't think of and was in front of my face the whole time. Just need to step away from it and get some outside advice. And yes there are a number of "bugs" within Windows so who knows that could be the problem right there. Thanks again!!

-NEX

Share this post


Link to post
Share on other sites
keep this post saved, if I think of any possibilities later, or have time to test some stuff I will let you know.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.