0

I am writing a batch for a new deployment of my company's software.. Here is what I have so far...

wscript.exe "invisible.vbs" "apache_start.bat" /wait
wscript.exe "invisible.vbs" "mysql_start.bat" /wait
"C:\Program Files\Internet Explorer\iexplore.exe" http://localhost

So as you can see, this script should start apache, then start mysql and then open the default page with IE.

The problem is if the user runs this script twice, it runs apache and mysql twice and loads two seperate instances. The solution I need is a way to check to see if the processes are already running and, if not, run the two wscript commands. I am absolutely horrible with shell, so please try to give specific responses! I am a software engineer, not a sysadmin. Thanks for the help!

2 Answers2

0

As a software engineer I think you have a leg up on scripting over some sysadmins...

Using PowerShell would make this easy. Use the following template to execute the services - you'll need to use it twice, and follow up with launching IE as above.

If ((Get-Process mysqlprocessname.exe)) {Write-Host Skipping MySQL}
Else { Start-Process ...}

This is going to take a few minutes for you to research the best way of starting a process with PowerShell. Also, you might want to pipe Start-Process to Out-Null so the script waits to start IE and Apache.

Others may want to chime in with a simpler way from a batch file.

Chris N
  • 7,239
  • 1
  • 24
  • 27
  • I wasn't clear. I actually need a way to do this with the default windows shell. My apologies – Andrew E. Rhyne May 21 '12 at 17:23
  • Here's a great post on how to use tasklist.exe in a batch file. I think it's what you need: http://stackoverflow.com/questions/4969595/exit-status-of-tasklist-in-batch-file – Chris N May 21 '12 at 17:26
0

For XAMPP, there is a pv.exe file in the apache/bin folder that XAMPP uses to see if a service is running. Look at WorldDrknss' answer in this thread for some great info: http://www.apachefriends.org/f/viewtopic.php?p=80047

The code to solve your problem is to modify your mysql_start.bat file to this:

@echo off 
apache\bin\pv mysqld.exe %1 >nul 
if ERRORLEVEL 1 goto Process_NotFound 
echo MySQL is running 
goto END 
:Process_NotFound 
echo Process %1 is not running 
mysql\bin\mysqld.exe --defaults-file=mysql\bin\my.ini --standalone --console
goto finish 
:finish

That will check if mysqld.exe is running. If it is, it just echos that out. If not, it starts the service.

Jonathon
  • 262
  • 4
  • 15