one more FOR question

  • Thread starter Thread starter djc
  • Start date Start date
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.
 
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
 
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.
 
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
 
Back
Top