FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » How to run a batch file using PHP?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: How to run a batch file using PHP? [message #179324 is a reply to message #179323] Fri, 05 October 2012 05:21 Go to previous messageGo to previous message
Fastian is currently offline  Fastian
Messages: 20
Registered: June 2012
Karma:
Junior Member
On Thursday, October 4, 2012 12:49:31 PM UTC+5, Álvaro G. Vicario wrote:
> El 04/10/2012 6:17, Fastian escribió/wrote:
>
>> I am trying to run a batch file using exec function in PHP. The program statement executes without any error but nothing happen and batch file is not executed.
>
>>
>
>> The batch file is v.simple with just two commands.This batch file runs fine when I run directly from cmd.But when I use exec function from my PHP page, I am unable to run this batch file. I am not interested in the output returned by exec( ) function's argument . I am just interested in the complete execution of the batch file.
>
>>
>
>> I have also tried using the exec() in following way but not successful:
>
>>
>
>> exec("c:\\windows\\system32\\cmd.exe /c $batchFileToRun");
>
>
>
> The exec() function already calls "cmd.exe" internally, there's no need
>
> to call it yourself.
>
>
>
> You've managed to omit all the relevant information:
>
>
>
> - What $batchFileToRun is. Is it a full path? Is it in a network drive?
>
> Does it contain spaces?
>
> - What the batch file does. Does it read or write files? Does it
>
> interact with the desktop?
>
> - What user you are running PHP as. Is it a command line script? Does
>
> Apache run it as LOCAL_SYSTEM?
>
> - What exec()'s return, output and return status are.
>
>
>
>
>
>> Is there any option available better than exec()?
>
>
>
> Given the question, I'd say proc_open() is "better" than exec(), but
>
> it's way more difficult to use. And it won't execute a script either if
>
> it cannot find it or does not have the appropriate permissions.
>
>
>
>
>
> --
>
> -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
>
> -- Mi sitio sobre programación web: http://borrame.com
>
> -- Mi web de humor satinado: http://www.demogracia.com
>
> --

To be precise, my batch file named show-preview.bat consist of only two commands:
latex first-program.tex
dvipng first-program.dvi

When I run show-preview.bat from cmd then they run successfully and I obtain the desired result.
But when I use exec('show-preview.bat'); I am finding the following error in apache_error_log:
'latex' is not recognized as an internal or external command, operable program or batch file.
'dvipng' is not recognized as an internal or external command, operable program or batch file.

Whereas both of these commands are working fine from the command prompt......... what you say?

I also tried to pass the absolute path of the bat file within exec() but it also do not work. Any idea?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: JOB - Sr. PHP Developer - Fort Lauderdale, FL - Relo/Sponsor OK
Next Topic: Regular Expression Help
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 04:00:24 GMT 2024

Total time taken to generate the page: 0.04201 seconds