Jump to content


Photo

Unable to run batch from PHP


  • Please log in to reply
9 replies to this topic

#1 NEX2NUN

NEX2NUN
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 July 2006 - 02:46 PM

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.

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

Any ideas?

  • Windows XP
  • IIS 5
  • PHP 5

-NEX


#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 02:51 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 NEX2NUN

NEX2NUN
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 July 2006 - 02:58 PM

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:

c:\reader\acrord32.exe /t c:\test.pdf

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

*shrugs*

#4 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 03:01 PM

http://drupal.org/node/14002

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

http://bugs.php.net/...arch_for=exec()
this will definitely probably help some go over those too and see if you find anything.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 28 July 2006 - 03:07 PM

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

#6 NEX2NUN

NEX2NUN
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 July 2006 - 03:38 PM

@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

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

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

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


#7 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 03:40 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#8 NEX2NUN

NEX2NUN
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 July 2006 - 03:43 PM

@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

#9 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 03:49 PM

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

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#10 NEX2NUN

NEX2NUN
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 July 2006 - 04:01 PM

Thanks man!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users