3

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 127.0.0.1 >NUL
"path\Gallio.Echo.exe" "path\MyAssembly.dll"
REM now, how do I stop the background process?
3
  • 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. Jul 2, 2009 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?" Jul 2, 2009 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, 2009 at 6:07

2 Answers 2

8

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.

SET TASK=%RANDOM%-SELENIUM-SERVER-%RANDOM%
start "%TASK%" java -jar "path\selenium-server.jar"
ping -n 5 127.0.0.1 >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:

SET TASK=%RANDOM%-SELENIUM-SERVER-%RANDOM%
start "%TASK%" cmd /k start java -jar "path\selenium-server.jar"
ping -n 5 127.0.0.1 >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<

1
  • 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, 2009 at 6:12
0

You can achieve it with visual basic script create a file called somehow.vbs

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd /c start /B java.exe ........... ", 0, False

using 0 and "False" as the values for these options, the script starts the java.exe command to run the jar in the background without displaying any window and without waiting for it to finish before continuing with the rest of the script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .