Reputation: 47
I'm trying to Loop through results of a command with FOR /F.
The command to actually run - C:\Program Files\my folder\command.exe
%installdir% is C:\Program Files\my folder\
The code I run is -
FOR /F "delims=, tokens=1,2" %%c in (results.txt) DO (
if %%d EQU [something] (
FOR /F "delims=: skip=2" %%e in ('%installdir%command.exe /checkstatus Client %%c') do (
echo %%e %%f
)
)
)
I'm guessing this is not running correctly because I need to use usebackq in some fashion, but I haven't managed to do so. Appreciate any help on this!
Upvotes: 0
Views: 2830
Reputation: 70923
FOR /F "delims=: skip=2" %%e in ('"%installdir%command.exe" /checkstatus ....
^ quotes ^
If your command includes spaces, you need to quote it.
The problem with this is that sametimes the cmd
instance that is started to handle the command to execute removes some double quotes (the quotes we added) and at the end we get a new error (see cmd /?
for more information)
To solve it, you will need to add ... more quotes.
FOR /F "delims=: skip=2" %%e in ('""%installdir%command.exe" /checkstatus ... "') do ....
quoted executable ^.......................^
quoted full command ^...........................................^
You will need usebackq
when
usebackq
to indicate that it is a file name.You can see both cases indicated if you execute for /?
Upvotes: 2