Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you run a .bat file from PHP?

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. I've checked the PHP manuals and googled around but can't find a good answer. Anyone know where I'm going wrong?

I'm running Windows 2003 Server and have successfully manually run the .bat file and it does what I need it to; I just need to be able to launch it programatically.

like image 275
undefined Avatar asked May 07 '09 17:05

undefined


People also ask

How do you run .BAT file?

To run a batch file, move to the directory containing the file and type the name of the batch file. For example, if the batch file is named "hope. bat," you'd type "hope" to execute the batch file.

How do I run a batch file from a website?

Just create a batch file and save in the location where your html file is there. this anchor tag will execute the (test. bat) batch file. After clicking on the link <TEST>, you will get the window prompting to open/save/close, if you will click on open then batch file will be executed.

What program runs a .BAT file?

When a batch file is run, the shell program (usually COMMAND.COM or cmd.exe) reads the file and executes its commands, normally line-by-line. Unix-like operating systems, such as Linux, have a similar, but more flexible, type of file called a shell script. The filename extension . bat is used in DOS and Windows.

How do you run a batch file in Javascript?

var wshShell = new ActiveXObject("WScript. Shell"); wshShell. Run("D:\\dir\\user. bat");


2 Answers

You might need to run it via cmd, eg:

system("cmd /c C:[path to file]"); 
like image 191
RichieHindle Avatar answered Oct 28 '22 18:10

RichieHindle


<?php exec('c:\WINDOWS\system32\cmd.exe /c START C:\Program Files\VideoLAN\VLC\vlc.bat'); ?> 
like image 36
mysoogal Avatar answered Oct 28 '22 18:10

mysoogal