Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to run a batch script that:

  • starts a background process (a Selenium RC server, if that matters);
  • waits until the background process starts to listening some port (or wait a fixed amount of time);
  • run some instructions;
  • stops the background process.

I wrote this:

start java -jar "path\selenium-server.jar" 
ping -n 5 >NUL
"path\Gallio.Echo.exe" "path\MyAssembly.dll"
REM now, how do I stop the background process?
share|improve this question
This is really not a job for a batch file. You may get it working but don't expect it to ever be reliable. This is screaming out for a programmatic solution. – John Gardeniers Jul 2 '09 at 22:19
Heh heh... "I need to nail this board, and all I have to pound them with is this package of eggs. Can you help me figure out how to do it?" – Evan Anderson Jul 2 '09 at 23:36
well, yeah, I agree! =) Now I´m trying to run that godamn jar as a service. But you could at least show some options instead of just throw the stones – Seiti Jul 3 '09 at 6:07
up vote 8 down vote accepted

You say "DOS", but I'd imagine you're meaning the Windows CMD shell. (MS-DOS isn't a multitasking operating system, after all.)

Okay, okay-- Here's a hack that I just worked up. I feel kinda dirty even suggesting this.

start "%TASK%" java -jar "path\selenium-server.jar"
ping -n 5 >NUL"
path\Gallio.Echo.exe" "path\MyAssembly.dll"
taskkill /FI "WINDOWTITLE eq %TASK%"

Assuming that the "java" command doesn't much with the window title, that "START" command will set the window title to "random number"-SELENIUM-SERVER-"random number", and then the TASKKILL will kill any windows with that title.

Eww... that makes me feel dirty.

If the "java" does mess with the window title, you could also do:

start "%TASK%" cmd /k start java -jar "path\selenium-server.jar"
ping -n 5 >NUL"
path\Gallio.Echo.exe" "path\MyAssembly.dll"
taskkill /T /FI "WINDOWTITLE eq %TASK%"

That really makes me feel dirty. That creates a CMD window with the random title that, in turn, starts the "java" in a separate window. The "/T" on TASKKILL will kill any child processes of the "FOO" window-- namely the "java" window.

I feel sick. >smile<

share|improve this answer
+1 for the dark side... – RBerteig Jul 2 '09 at 23:01
thanks for your answer! (and by seeing that now I´m thinking if there are some other solutions to the problem I´m facing =) – Seiti Jul 3 '09 at 6:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.