P
P
Pavel2020-07-26 08:05:06
cmd/bat
Pavel, 2020-07-26 08:05:06

Why is the cmd loop not working?

set cod4=qbittorrent.exe
FOR /F %%x IN ('TASKLIST /NH /FI "IMAGENAME eq %cod4%"') DO IF %%x == %cod% goto Found

does not find the program in the tasks and does not go to Found, what am I missing?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Bezrukov, 2020-07-26
@NortheR73

And so?

@echo off
set cod4=qbittorrent.exe
FOR /F %%x IN ('TASKLIST /FI "IMAGENAME eq %cod4%"') DO IF %%x == %cod4% goto Found
:Found
echo Found

TASKLIST /NH /FI "IMAGENAME eq %cod4%"

this command is already searching for the process you need ... Why are you driving the search results into a loop?
Have you considered the option with Powershell?
$cod4 = "qbittorrent.exe"
Get-Process | where{$_.ProcessName -like $cod4} | select ProcessName

R
res2001, 2020-07-26
@res2001

Add a space between the double quote and the single quote at the end of tasklist. When they are written together they do not work as they should. Now I don't have Windows at hand, so I can't check. But this is a well-known bug feature, I stepped on it myself.
Well, the Found label, of course, must be present in the script.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question