windows 检查应用程序是否仍在从批处理文件运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/286392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Checking if an application is still running from a batch file?
提问by Mikael S?derstr?m
How to use batch file to check if an application still running or not? If the application still running, this process will loop again and again. Else, there will be error message.
如何使用批处理文件检查应用程序是否仍在运行?如果应用程序仍在运行,这个过程将一次又一次地循环。否则会出现错误提示。
Thank you very much
非常感谢
回答by
in windows you kan use pstoolspslist to check if a process name is running by using a .cmd script like the following. Pslist will return ERRORLEVEL 0 if the process is running, 1 if not.
在 Windows 中,您可以使用pstoolspslist 通过使用如下所示的 .cmd 脚本来检查进程名称是否正在运行。如果进程正在运行,Pslist 将返回 ERRORLEVEL 0,否则返回 1。
@echo off
CommandYouWillRun.exe
rem waiting for the process to start
:startcmd
sleep 1
c:\path\to\pslist.exe CommandYouWillRun > NUL
IF ERRORLEVEL 1 goto startcmd
rem the process has now started
:waitforcmd
sleep 1
c:\path\to\pslist.exe CommandYouWillRun > NUL
IF ERRORLEVEL 1 got finished
goto waitforcmd
:finished
echo "This is an error message"
回答by Mark
Linux ?
Linux ?
ps aux | grep task | wc -l
ps辅助| grep 任务 | wc -l
where task is the name of the task (e.g. "apache2" - quotes not needed)
其中 task 是任务的名称(例如“apache2” - 不需要引号)
回答by Mikael S?derstr?m
You can write a powershell-script and use get-process with filtering.
您可以编写一个 powershell 脚本并使用 get-process 进行过滤。
http://www.computerperformance.co.uk/powershell/powershell_process.htm
http://www.computerperformance.co.uk/powershell/powershell_process.htm
回答by javamonkey79
Perhaps you mean tasklist? You can run that from the command line to get all running processes in windows...for the rest of what you are asking I think you will need to be more specific.
也许你的意思是任务列表?您可以从命令行运行它以获取 Windows 中所有正在运行的进程......对于您要问的其余部分,我认为您需要更具体。