Pipes in for loop

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.
 
B

Bill Stewart

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top