in batch how do i use taskkill properly

空扰寡人 提交于 2019-12-12 22:15:33

问题


I need to shutdown a program (minecraft server). I think taskkill will do the job

@echo on
TASKKILL /F /IM Minecraft server /T
echo killed!

I asked questions before of how to auto type "stop" in the console of the server, but they didn't work. I don't want to download any extra programs. Just batch, VBScript, or Java. I would prefer batch though.

Hope I made some sense anyway thanks!


回答1:


I think you're looking for this:

@echo off
for /f "tokens=2" %%a in ('tasklist^|find /i "javaw.exe"') do (set pid=%%a)
echo %pid%
taskkill /pid %pid%
pause

This will get the PID (temporary "ID" for a proccess/task), and kill it/the source. This will take a random "javaw.exe" though, so if you have more than one 'javaw.exe' / java proccess open at a time, it will take a random one, find its' PID and kill it. But as for my experience when running a Minecraft server you dont want to have many unnessecary programs open in the Background - so you can safely use this as long as you only run one 'javaw.exe' at a time :)

Hope this help!




回答2:


The correct Syntax for Taskkill

taskkill [/s Computer] [/u Domain\User [/p Password]]] [/fi FilterName] [/pid ProcessID]|[/im ImageName] [/f][/t]

To kill Minecraft Server

TaskKill /F /IM javaw.exe

Hope this Helps.



来源:https://stackoverflow.com/questions/30540934/in-batch-how-do-i-use-taskkill-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!