views:

3961

answers:

3

Can anyone tell me how to execute a .bat file from a PHP script?

I have tried - exec("C:[path to file]"); system("C:[path to file]");

nothing is working. Ive checked the PHP manuals and googled around but cant find a good answer. Anyone know where im going wrong?

I'm running windows 2003 server and have successfully manually ran the .bat file and it does what i need it to, I just need to be able to launch it programatically.

thanks

+8  A: 

You might need to run it via cmd, eg:

system("cmd /c C:[path to file]");
RichieHindle
There is also some great documentation for the SYSTEM() as well:http://us3.php.net/system
Phill Pafford
Thanks - that worked.
undefined
how can i return the results from running the .bat file to PHP so that I can retrieve a value i need - and is this just slicing a string?
undefined
@Stephen: To read output from the process, you need to run it with popen. See http://uk3.php.net/popen
RichieHindle
A: 
<?php
exec('c:\WINDOWS\system32\cmd.exe /c START C:\Program Files\VideoLAN\VLC\vlc.bat');
?>
mysoogal
A: 

Hello, I have tried system("cmd /c c:\temp\mkdir.bat"); in my script.. but I seem to get Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\dexter\index.php on line 35

A little help, no doubt I will kick myself when someone tells me the answer!

Hi this is probably something quite simple like a missing semicolon - you could include more of your code so we can see what might be wrong, or check the line mentioned for missing semicolon or unclosed double quotes for example.
undefined