Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php shell_exec bash.exe does not working in Window XP IIS

Tags:

bash

php

generatedb.php

 <?php
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    echo 'This is a server using Windows!';
    $output = shell_exec("C:\\cygwin\\bin\\bash.exe --login -c C:\\cygwin\\bin\\mysql2sqlite.sh -h 127.0.0.1 -u root -pApacheah64 db_shuttlebus tbl_driver tbl_location tbl_rate tbl_route tbl_routeid tbl_vehicle | C:\\cygwin\\sqlite3.exe  C:\\Inetpub\\wwwroot\\BusTicket\\exportdatabase\\database.sqlite");
    echo "<pre>".$output."</pre>";
} else {
    echo 'This is a server not using Windows!';
    $output = shell_exec("bash mysql2sqlite.sh -h 127.0.0.1 -u root -pApacheah64 db_shuttlebus tbl_driver tbl_location tbl_rate tbl_route tbl_routeid tbl_vehicle | sqlite3  /var/www/BusTicket/exportdatabase/database.sqlite");
    echo "<pre>".$output."</pre>";
}

?>

this is the error out the output

Warning: shell_exec(): Unable to execute 'C:\cygwin\bin\bash.exe --login -c
C:\cygwin\bin\mysql2sqlite.sh -h 127.0.0.1 -u root -pApacheah64 db_shuttlebus tbl_driver  
tbl_location tbl_rate tbl_route tbl_routeid tbl_vehicle | C:\cygwin\sqlite3.exe 
C:\Inetpub\wwwroot\BusTicket\exportdatabase\database.sqlite' in   
C:\Inetpub\wwwroot\BusTicket\exportdatabase\generatedb.php on line 4 

if i manually open cmmand promt and run the command are working fine, but when in PHP then it is can't work. why?

i have checked php.ini safe mode are off and disable_functions = are blank.

and this is my phpinfo.php

enter image description here

this is i m using cmd.exe to run the command, it is working

enter image description here

like image 656
John Walker Avatar asked Jan 27 '26 21:01

John Walker


1 Answers

Knowing IIS, there are probably multiple possible explanations. Here's one I found on http://www.php.net/shell_exec

Got the error "Unable to execute..." when trying to run an external program with shell_exec under Windows XP, IIS 5, php 4.3.7 Solved by giving the IIS user (IUSR_...) execution privileges on the system file %systemroot%\system32\cmd.exe This should be used carefully because may represent a server's security hole.

HTH.

like image 159
Ruud Helderman Avatar answered Jan 29 '26 09:01

Ruud Helderman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!