Shutdown the computer when a particular program shuts down

Asked

Viewed 87 times

3

I’m turning an old CPU into a Minecraft server. When turning the computer on, I can get it to open the server via script (starting a -jar file), however, I would like to have it shut down as soon as the -jar program closes.

The script I have is this, which only makes it open

@ECHO OFF
start java -Xms1G -Xmx1G -jar minecraft_server.jar nogui
pause

They could tell me the code that makes the computer shut down as soon as "minecraft_server.jar" is closed?

1 answer

1


To turn off the computer, you can use the command shutdown passing as parameter /s, as follows:

shutdown /s

Since you only want to shut down after the program shuts down, you can create your script using the parameter /wait of command start, with this the script awaits the termination of the program executed by start.


Your script would look more or less like this:

@ECHO OFF
start /wait java -Xms1G -Xmx1G -jar minecraft_server.jar nogui
shutdown /s

As soon as the java is closed, will fall on the shutdown command.


Documentations:

https://docs.microsoft.com/pt-br/windows-server/administration/windows-commands/shutdown

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/start

Browser other questions tagged

You are not signed in. Login or sign up in order to post.