3

I'm starting a Java background process (Solr) from a batch file with

start /b java -jar ...

The problem is that start /b will shield the process from SIGINT signals, see help start. This means that taskkill /pid ... won't work and taskkill /f /pid ... will kill the process without letting it execute shutdown hooks first.

Is there another way to start the background process on Windows from a .bat file without opening a window and without shielding it from SIGINT? Or is there another way of sending a signal to the java VM so that Solr shuts down gracefully when running from start /b?

I'd like to use a normal batch script rather than VBScript or similar if possible as this is what most our users probably know best.

jerico
  • 1,659
  • 15
  • 20

3 Answers3

1

Not sure how to do it in a .bat file, but with Powershell you can do this:

Start-Process java -ArgumentList "-jar start.jar <args>" -WindowStyle Hidden

Then you can stop the process normally.

Run get-help Start-Process -detailed for more info on options - you can also easily run the process as a different user and other things that the old start won't let you do.

Dan Fitch
  • 2,480
  • 2
  • 23
  • 39
  • Thanks for taking the time to answer! :-) I'd rather avoid having to depend on Powershell, though, see question. – jerico Dec 01 '12 at 15:31
  • 1
    Thanks, Dan! I didn't realize that my URL got truncated. Should be fixed now. Upvoted your answer because it will probably help others. – jerico Dec 05 '12 at 01:26
0

Have you tested that? I ran:

START /B notepad.exe

and then closed it using

TASKKILL /PID 123456
aphoria
  • 19,796
  • 7
  • 64
  • 73
  • Thanks for the answer. Yes, that works. Unfortunately the same is not true for the case I described. When I use `start java ...`, taskkill works, not so if I use `start /b java ...`. Maybe the difference is that notepad opens a window while my process runs with its output redirected to a log file? – jerico Nov 29 '12 at 19:42
0

I found a workaround for my specific case (solr + jetty), see http://alaminsumon.blogspot.com.br/2009/06/how-to-stop-and-start-jetty-server-from.html

jerico
  • 1,659
  • 15
  • 20