user3219834
user3219834

Reputation: 37

How do I create a batch loop with commands in the list?

I am trying to create a batch script with a for loop that contains commands in the list. my problem is when i run commands with arguments it reads the space as a list deliminator. I intend to have several commands in the list, but for now it is only 2. the %1 is the file to write the output to.

for %%G IN ("ipconfig /all" "net start") DO (
 echo %%G >> %1
 %%G >> %1 
)

Upvotes: 2

Views: 65

Answers (1)

npocmaka
npocmaka

Reputation: 57252

@echo off
break>%1
for %%G IN ("ipconfig /all" "net start") DO (
 echo "%%~G"
 %%~G
)>>%1

use %%~G to dequote the token.

Upvotes: 2

Related Questions