NEX2NUN Posted July 28, 2006 Share Posted July 28, 2006 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]<?phpexec('test.bat');?>[/code]Any ideas?[list][*]Windows XP[*]IIS 5[*]PHP 5[/list]-NEX Quote Link to comment https://forums.phpfreaks.com/topic/15891-unable-to-run-batch-from-php/ Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/15891-unable-to-run-batch-from-php/#findComment-65195 Share on other sites More sharing options...
NEX2NUN Posted July 28, 2006 Author Share Posted July 28, 2006 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* Quote Link to comment https://forums.phpfreaks.com/topic/15891-unable-to-run-batch-from-php/#findComment-65197 Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 http://drupal.org/node/14002http://us3.php.net/manual/en/ref.exec.phpread the user comments there, it has some stuff about windows.http://bugs.php.net/search.php?cmd=display&search_for=exec%28%29this will definitely probably help some go over those too and see if you find anything. Quote Link to comment https://forums.phpfreaks.com/topic/15891-unable-to-run-batch-from-php/#findComment-65198 Share on other sites More sharing options...
kenrbnsn Posted July 28, 2006 Share Posted July 28, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/15891-unable-to-run-batch-from-php/#findComment-65200 Share on other sites More sharing options...
NEX2NUN Posted July 28, 2006 Author Share Posted July 28, 2006 @kenYes 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.@businessman332211I 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] Quote Link to comment https://forums.phpfreaks.com/topic/15891-unable-to-run-batch-from-php/#findComment-65211 Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/15891-unable-to-run-batch-from-php/#findComment-65212 Share on other sites More sharing options...
NEX2NUN Posted July 28, 2006 Author Share Posted July 28, 2006 @businessman33221I 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 Quote Link to comment https://forums.phpfreaks.com/topic/15891-unable-to-run-batch-from-php/#findComment-65214 Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 keep this post saved, if I think of any possibilities later, or have time to test some stuff I will let you know. Quote Link to comment https://forums.phpfreaks.com/topic/15891-unable-to-run-batch-from-php/#findComment-65217 Share on other sites More sharing options...
NEX2NUN Posted July 28, 2006 Author Share Posted July 28, 2006 Thanks man! Quote Link to comment https://forums.phpfreaks.com/topic/15891-unable-to-run-batch-from-php/#findComment-65220 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.