英文:
Kill slow command after some time and return value
问题
这是您要的翻译部分:
我有一个管道TASKLIST | FINDSTR命令,它可能需要很长时间才能完成。我不想等太久,所以我想停止使用FINDSTR进行搜索,并在例如5秒后只获取ERRORLEVEL 1值。
这个脚本需要检查特定的EXE是否在运行,如果没有在运行,则打开它。
@echo off
:B
set Poro=CapsuleFarmerEvolved.exe
TASKLIST /fi "imagename eq %Poro%" 2>nul | FINDSTR /i %Poro%
if ERRORLEVEL 0 (GOTO :B) else (start "" CapsuleFarmerEvolved.exe)
GOTO :B
我已经按照您的要求只提供了翻译,没有包含额外的内容或回答其他问题。
英文:
I've got a piped TASKLIST | FINDSTR command, which can take long time to finish. I don't want to wait too long for it, so I want to stop searching with FINDSTR and just get ERRORLEVEL 1 value, after for example 5s.
This script got to look if the specific EXE is running, and if it's not - open it.
@echo off
:B
set Poro=CapsuleFarmerEvolved.exe
TASKLIST /fi "imagename eq %Poro%" 2>nul | FINDSTR /i %Poro%
if ERRORLEVEL 0 (GOTO :B) else (start "" CapsuleFarmerEvolved.exe)
GOTO :B
I've tried adding timeout before the TASKLIST, but since it's piped, it doesn't work.
I was wondering maybe about creating a different .bat with this exact command and somehow kill the whole process, then return the value to the main script.
That is my first take to create a script, so please forgive me lack of basic knowlege, but I'd tried my best before posting this
答案1
得分: 1
这应该可以做到,然而这仍然是一个荒谬的想法,即使用一个永无止境的脚本来监视和重新启动一个应用程序,当它不再运行时。
@Echo Off
Set "Poro=CapsuleFarmerEvolved.exe";
:Loop
%SystemRoot%\System32\tasklist.exe /Fi "Status Eq Running" /Fi "ImageName Eq %Poro%" 2>NUL | %SystemRoot%\System32\find.exe /I "%Poro%" 1>NUL || Start "" "P:\athTo\%Poro%"
%SystemRoot%\System32\timeout.exe /T 5 /NoBreak 1>NUL
GoTo Loop
英文:
This should do it, however this is still a ridiculous idea, i.e. using a never-ending script to monitor, and restart an application, when it is no longer running.
@Echo Off
Set "Poro=CapsuleFarmerEvolved.exe"
:Loop
%SystemRoot%\System32\tasklist.exe /Fi "Status Eq Running" /Fi "ImageName Eq %Poro%" 2>NUL | %SystemRoot%\System32\find.exe /I "%Poro%" 1>NUL || Start "" "P:\athTo\%Poro%"
%SystemRoot%\System32\timeout.exe /T 5 /NoBreak 1>NUL
GoTo Loop
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论