Jump to content
Sign in to follow this  
hybrid

Windows Batch Scripts

Recommended Posts

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:

 

@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

"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:

 

cmd.jpg

 

Any help would be appreciated,

 

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

Share this post


Link to post
Share on other sites

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

 

such as

 

@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

 

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

echo.

 

cheers

 

anyweb

Share this post


Link to post
Share on other sites

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 :huh: ), so when i ran:

 

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:

 

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

Share this post


Link to post
Share on other sites
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...