one more FOR question

D

djc

I previously mixed up 2 different issues in a post... The one issue was
resolved, which I'm greatful for. Here is the other question I had that I
accidentally mixed in that post.

Example command:
FOR /F "skip=3" %i IN ('net view') do pslist %i | findstr "processname"

Above command works fine. However if I tried this:
FOR %i IN ('net view | findstr /i "\\"') do pslist %i | findstr
"processname"

I get an error stating that '|' was unexpected. The '|' its refering to is
the one right after the 'IN' part of the FOR command. Does this mean you
cannot
pipe commands together there? or am I just doing it wrong?

any input is appreciated. thanks.
 
M

Matthias Tacke

djc said:
I previously mixed up 2 different issues in a post... The one issue was
resolved, which I'm greatful for. Here is the other question I had that I
accidentally mixed in that post.

Example command:
FOR /F "skip=3" %i IN ('net view') do pslist %i | findstr "processname"

Above command works fine. However if I tried this:
FOR %i IN ('net view | findstr /i "\\"') do pslist %i | findstr
"processname"

The /F is necessary to embed commands. And to avoid the pipe sign being
interpreted as part of the for itself you have to escape it with a caret.
I get an error stating that '|' was unexpected. The '|' its refering to is
the one right after the 'IN' part of the FOR command. Does this mean you
cannot
pipe commands together there? or am I just doing it wrong?

FOR /F %i IN ('net view^|findstr /i "\\"') do pslist %i|findstr "processname"

HTH
 
D

djc

beautiful! thank you!

Dean Wells said:
Prefix it with a carat (^).

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
I previously mixed up 2 different issues in a post... The one issue
was resolved, which I'm greatful for. Here is the other question I
had that I accidentally mixed in that post.

Example command:
FOR /F "skip=3" %i IN ('net view') do pslist %i | findstr
"processname"

Above command works fine. However if I tried this:
FOR %i IN ('net view | findstr /i "\\"') do pslist %i | findstr
"processname"

I get an error stating that '|' was unexpected. The '|' its refering
to is the one right after the 'IN' part of the FOR command. Does this
mean you cannot
pipe commands together there? or am I just doing it wrong?

any input is appreciated. thanks.
 
D

djc

Thank you!

Matthias Tacke said:
The /F is necessary to embed commands. And to avoid the pipe sign being
interpreted as part of the for itself you have to escape it with a caret.


FOR /F %i IN ('net view^|findstr /i "\\"') do pslist %i|findstr "processname"

HTH
 

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