FOR usage question

  • Thread starter Thread starter djc
  • Start date Start date
D

djc

I'm trying to run a command that will check each computer on the network
(via net view output) to see if a specific process is running. I am using
Net View, FOR, and sysinternal's pslist. I'm assuming most in this forum
know what pslist does but just in case, it retrieves the running processes
for a local or remote computer. I know I can accomplish what I want via a
few seperate steps or commands but my intention is to make this one command.
I am no expert at this so if you think I should not do that and just create
a batch file then so be it. I will.

here is what I tried last:
FOR /F "skip=8" %i in ('net view') do pslist %i | findstr "processname"

I get an error stating that '|' was unexpected. Does this mean you cannot
pipe commands together when using the FOR command? or am I just doing it
wrong?

I know pslist has a parameter that you can use to specify a specific process
but I still would want to only display the actual lines with the process
name, not all the header information from the pslist program... there would
be too much output. So I think I need to be able to use the pipe function or
create a batch. But again, I'm no expert.

any input is appreciated. Thanks.
 
Your code works here (I'm diring the "There is no entries in the list").

C:\Documents and Settings\David Candy>FOR /F %i in ('net view') do dir %i |sort

C:\Documents and Settings\David Candy>dir There | sort
File Not Found


Directory of C:\Documents and Settings\David Candy
Volume in drive C has no label.
Volume Serial Number is F0FD-FD80
 
thanks for the reply David. I made a mistake in my post. The error I
mentioned did not match up with the command I posted. That error was from
something else I tried. Whoops. The issue that was happening with the
specific command I posted was that several screen fulls of text were
scrolling by without pausing... I thought that the MORE command was not
working. However, I just realized what was happening. There is output for
each computer. Essentially it is a seperate command on each computer name.
So when several command's output did not 'need' the MORE command ran
sequentially lots of info scrolled of the screen. The MORE command of course
only happened on each individual command that needed it... I was mistaken to
think that MORE was going to operate on the FOR loop as a whole. I guess I
will need to separate this into a batch or at least 2 commands after all...
unless anyone else has any ideas.

thanks again.

"David Candy" <.> wrote in message
Your code works here (I'm diring the "There is no entries in the list").

C:\Documents and Settings\David Candy>FOR /F %i in ('net view') do dir %i
|sort

C:\Documents and Settings\David Candy>dir There | sort
File Not Found


Directory of C:\Documents and Settings\David Candy
Volume in drive C has no label.
Volume Serial Number is F0FD-FD80
 
djc said:
thanks for the reply David. I made a mistake in my post. The error I
mentioned did not match up with the command I posted. That error was from
something else I tried. Whoops. The issue that was happening with the
specific command I posted was that several screen fulls of text were
scrolling by without pausing... I thought that the MORE command was not
working. However, I just realized what was happening. There is output for
each computer. Essentially it is a seperate command on each computer name.
So when several command's output did not 'need' the MORE command ran
sequentially lots of info scrolled of the screen. The MORE command of course
only happened on each individual command that needed it... I was mistaken to
think that MORE was going to operate on the FOR loop as a whole. I guess I
will need to separate this into a batch or at least 2 commands after all...
unless anyone else has any ideas.

Your analysis of the error you made was bang on. But you can turn a block of
commands into what is effectively a single command by enclosing them in
parentheses. Try doing it this way by changing this:

FOR /F "skip=8" %i in ('net view') do pslist %i | findstr "processname"

to this:

(
FOR /F "skip=8" %i in ('net view') do pslist %i
) | findstr "processname"

No guarantees for findstr, as I only tested with "MORE", i.e.:

(
for /l %%F in (1,1,50) do @echo %%F
) | more

/Al
 
sweet! thanks for the info!

Al Dunbar said:
mistaken

Your analysis of the error you made was bang on. But you can turn a block of
commands into what is effectively a single command by enclosing them in
parentheses. Try doing it this way by changing this:

FOR /F "skip=8" %i in ('net view') do pslist %i | findstr "processname"

to this:

(
FOR /F "skip=8" %i in ('net view') do pslist %i
) | findstr "processname"

No guarantees for findstr, as I only tested with "MORE", i.e.:

(
for /l %%F in (1,1,50) do @echo %%F
) | more

/Al
via
 
Back
Top