View Full Version : Pipes in for loop


Fyodor Koryazhkin
09-29-2005, 04:00 PM
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.

Bill Stewart
09-29-2005, 04:06 PM
Fyodor Koryazhkin wrote:

> 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

--
Bill Stewart