Linux-Noob Forums
Windows Batch Scripts - Printable Version

+- Linux-Noob Forums (https://www.linux-noob.com/forums)
+-- Forum: Windows Noob (https://www.linux-noob.com/forums/forum-5.html)
+--- Forum: How Do I? (https://www.linux-noob.com/forums/forum-70.html)
+--- Thread: Windows Batch Scripts (/thread-2266.html)



Windows Batch Scripts - hybrid - 2006-01-06


OK, here's a bit of background on what I'm trying to do. I need to show someone a PHP/MySQL powered website (built and tested in Linux) without uploading to a server. The only system I can get to is a laptop running Windows XP Pro, and I don't want to boot a live Linux distro.

 

I have installed Apache/PHP/MySQL on this laptop and they are talking to each other OK. What I want to build is a short batch script that will start MySQL, and then Apache and then launch a browser to view automatically without fumbling around in the CLI. I am running Apache *not* as a service. Here is my code so far:

 



Code:
@echo off
echo Now starting test server, please wait...
echo.
echo.
echo.
rem pause
echo Starting database server...
echo.
net start mysql
rem pause
echo.
echo Starting web server...
echo.
"C:\Program Files\Apache Group\Apache2\bin\apache.exe"
pause
echo.
echo Now loading Internet Explorer to show the page...
rem pause
echo.
"C:\Program Files\Internet Explorer\iexplore.exe" "http://127.0.0.1:8080"
echo.
echo The server is now started, please go to your Internet Explorer window to view the page
echo.
echo.
echo.
echo ===========================================================
echo To stop the servers, please press any key.
echo (Apache must be stopped manually by closing the CMD window)
echo ===========================================================
pause>nul
echo.
echo Stopping database server...
echo.
net stop mysql
echo.
echo Done.
echo.
echo Press any key to quit.
pause>nul




 

The problem is, the line



Code:
"C:\Program Files\Apache Group\Apache2\bin\apache.exe"




just causes the script to hang, as Apache is running in the same CMD window. Is there a way like Bourne Shell's & to run it in the background? I have tried using the start command, but it doesn't seem to start the server properly.

 

Output of the script:

 

[Image: cmd.jpg]

 

Any help would be appreciated,

 

(PS - IE isn't my choice ;) )




Windows Batch Scripts - anyweb - 2006-01-06


use a separate batch script to start apache, and call that script from within the first one

 

such as

 



Code:
@echo off
echo Now starting test server, please wait...
echo.
echo.
echo.
rem pause
echo Starting database server...
echo.
net start mysql
rem pause
call start_apache.bat




 

start_apache. bat could simply be like so

 



Code:
echo.
echo Starting web server...
echo.
"C:\Program Files\Apache Group\Apache2\bin\apache.exe"

echo.




 

cheers

 

anyweb




Windows Batch Scripts - hybrid - 2006-01-07


This didn't work, because once again the script start_apache.bat doesn't end until Apache terminates - and Apache only terminates when it is manually killed.

 

I worked out how to do it though, apparently the start command takes the window title of the new window as the first argument and the command second (how intuitive o_O ), so when i ran:

 



Code:
start "C:\Program Files\Apache Group\Apache2\bin\apache.exe"




I was simply creating a blank command window with the title of C:\Program Files\Apache Group\Apache2\bin\apache.exe, that didn't run anything, so changing the line to:

 



Code:
start "Apache (do NOT close until finished)" "C:\Program Files\Apache Group\Apache2\bin\apache.exe"




sets the title of the window to Apache (do NOT close until finished), and then actually runs the command inside that new window.

 

Thanks for the help anyway, anyweb. :)