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.
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.
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.
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.
var wshShell = new ActiveXObject("WScript. Shell"); wshShell. Run("D:\\dir\\user. bat");
You might need to run it via cmd
, eg:
system("cmd /c C:[path to file]");
<?php exec('c:\WINDOWS\system32\cmd.exe /c START C:\Program Files\VideoLAN\VLC\vlc.bat'); ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With