0

I facing error while running the below php script. My php script having the little code for executing the .bat file which is located on my local server.

PHP file code : -

<?php
    system("cmd /c C:\Users\my_computer_name\Desktop\sample.bat");
?>

sample.bat file code : -

@echo off
title This is your first batch script!
echo Welcome to batch scripting!
start calc.exe

When i remove start calc.exe from .bat file code it works fine.

Thank you in Advance....

Harsh Barach
  • 947
  • 9
  • 18
  • 1
    Possible duplicate of [How to execute batch file via PHP?](https://stackoverflow.com/questions/19088379/how-to-execute-batch-file-via-php) – capcj May 23 '17 at 10:52
  • Can you tell us what the problem is? – WasteD May 23 '17 at 10:52
  • When i am trying to run the script the server is loading and not getting the response. – Harsh Barach May 23 '17 at 10:52
  • @CarlosAlexandre my question is totally different. – Harsh Barach May 23 '17 at 10:54
  • Once try with `exec` function in PHP. You can run commands using the `exec` function. `http://php.net/manual/en/function.exec.php` – phpfresher May 23 '17 at 11:03
  • @phpfresher I have already tried with exec but it is not working for my code. – Harsh Barach May 23 '17 at 11:05
  • You're starting a program inside a bat with an process started by PHP, I don't think you can do that, @HarshBarach – capcj May 23 '17 at 11:06
  • @CarlosAlexandre I think it is possible but i can not find the way to do so. – Harsh Barach May 23 '17 at 11:07
  • https://stackoverflow.com/questions/14059588/how-can-i-start-a-windows-gui-program-using-php Try that – capcj May 23 '17 at 11:07
  • @CarlosAlexandre The thread suggested by you having the direct execution of the .exe file but in my case i want to run .exe file from .bat file by php script. – Harsh Barach May 23 '17 at 11:10
  • Exec your bat after that, your exe or check your permissions with the bat, possibly the windows don't allowing you doing that with the apache instance or some kind of stuff – capcj May 23 '17 at 11:11
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/144925/discussion-between-harsh-barach-and-carlos-alexandre). – Harsh Barach May 23 '17 at 11:12

0 Answers0