1

如何使用批处理文件检查应用程序是否仍在运行?如果应用程序仍在运行,则此过程将一次又一次地循环。否则,会有错误信息。

非常感谢

4

4 回答 4

5

在 Windows 中,您可以使用pstools pslist 通过使用 .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"
于 2008-11-13T07:38:53.943 回答
2

Linux?

ps辅助| grep 任务 | wc -l

其中 task 是任务的名称(例如“apache2” - 不需要引号)

于 2008-11-13T07:02:52.580 回答
1

您可以编写一个 powershell 脚本并将 get-process 与过滤一起使用。

http://www.computerperformance.co.uk/powershell/powershell_process.htm

于 2008-11-13T07:45:12.323 回答
0

也许你的意思是任务列表?您可以从命令行运行它以获取 Windows 中的所有正在运行的进程......对于您所要求的其余内容,我认为您需要更具体。

于 2008-11-13T07:00:28.780 回答