查找Windows批处理过程开业 [英] Find opened process in Windows batch
问题描述
我想写code哪些循环,如果某个进程被打开或不告诉。它应该是一个循环,会告诉我实时如果过程被打开或没有。换句话说,该程序被打开时的文本将会改变,当它关闭再次改变。相反,我得到的是具有相同文本的洪水,并没有表现出回声报在它下面。
我试过这样:
关闭@echo
转到xera
:开始
任务列表/ FIIMAGENAME EQ的notepad.exe|查找/ I的notepad.exe> NUL
IF%ERRORLEVEL%EQU 0 ECHO被打开
IF%ERRORLEVEL%EQU 1 ECHO心不是开
:xera
集/ P=状态:<&NUL放大器;拨打://开始的code得到了'卡'在这里
ECHO文本2(犯规秀)
暂停> NUL
您不会终止您的子程序:启动
正确。请尝试以下操作:
关闭@echo
转到xera
:开始
任务列表/ FIIMAGENAME EQ的notepad.exe|查找/ I的notepad.exe> NUL
IF%ERRORLEVEL%EQU 0 ECHO被打开
IF%ERRORLEVEL%EQU 1 ECHO心不是开
退出/ B
:xera
集/ P=状态:<&NUL放大器;拨打:启动
ECHO文本2(犯规秀)
暂停> NUL
我插入退出/ B
让命令间preTER的呼叫后返回到命令
实际上把它称为声明。你也可以使用转到:EOF
来代替。键入呼叫/?
有关如何调用子程序批次的详细信息。
I'm trying to write code which loops and tells if a certain process is opened or not. It should be a loop that will show me in real time if the process is opened or not. In other words, a text will change when the program is opened and change again when it's closed. Instead what I got was a flood with the same text and it doesn't show the 'echos' below it.
I tried this:
@echo off
goto xera
:start
tasklist /FI "IMAGENAME eq notepad.exe" | find /I "notepad.exe" > nul
IF %ERRORLEVEL% equ 0 ECHO is opened
IF %ERRORLEVEL% equ 1 ECHO isnt opened
:xera
set /p "=Status: " <nul &call :start //the code got 'stuck' here
ECHO Text 2 (doesnt show)
pause>nul
You are not terminating your sub-routine :start
correctly. Try the following:
@echo off
goto xera
:start
tasklist /FI "IMAGENAME eq notepad.exe" | find /I "notepad.exe" > nul
IF %ERRORLEVEL% equ 0 ECHO is opened
IF %ERRORLEVEL% equ 1 ECHO isnt opened
exit /b
:xera
set /p "=Status: " <nul &call :start
ECHO Text 2 (doesnt show)
pause>nul
I inserted exit /b
which tells the command interpreter to return to the command after the call
statement that actually called it. You could also use goto :EOF
instead. Type call /?
for more information on how to call sub-routines in batch.
这篇关于查找Windows批处理过程开业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!