Pipes in for loop

  • Thread starter Thread starter Fyodor Koryazhkin
  • Start date Start date
F

Fyodor Koryazhkin

Hi,
I am wondering if I can use pipes in for loops in a command shell.
Here is an example of disireble use:

for /F "tokens=*" %f in ('net start | findstr "VM"') do @echo %f
This does not work saying "| was unexpected at this time." What wrong with
a syntax?

The purpose of this is to find particular services and then stop them.

I would appreciate any other solution is any.

Thank you
Fyodor.
 
Fyodor said:
Hi, I am wondering if I can use pipes in for loops in a command
shell. Here is an example of disireble use:

for /F "tokens=*" %f in ('net start | findstr "VM"') do @echo %f

This does not work saying "| was unexpected at this time." What wrong
with a syntax?

Hello Fyodor,

You need to escape the "|" character with the "^" character; e.g.

for /f "tokens=*" %f in ('net start ^| findstr "VM"') do @echo %f
 
Back
Top