Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/15891-unable-to-run-batch-from-php/
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*
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.
@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]
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.
@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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.