Linux-Noob Forums

Full Version: Windows Batch Scripts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

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 ;) )


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


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. :)