Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - redirecting standar output when using [System.Diagnostics.Process]::Start

Reply
 
Old 07-23-2007   #1 (permalink)
freddy chavez


 
 

redirecting standar output when using [System.Diagnostics.Process]::Start

Hello all. I want to execute a command against a bunch of IP nodes (servers,
routers) in PARALLEL (not one after another). I demonstrate my case using
PING, but it could be another tool.

The following code works ok:

$nodes="server1", "server2", "router1" #... a lot of nodes
$nodes | foreach {[System.Diagnostics.Process]::Start("ping.exe","$_") }

Now, i need to log all the responses to a unique file for every node, so I
try:

$nodes | foreach {[System.Diagnostics.Process]::Start("ping.exe","$_ >
$_.log 2>&1") }

But it's not working. The problem, i think, is the redirection of the
standard output and standard error.
Thanks for your help.

Regards,
Freddy Chavez.



My System SpecsSystem Spec
Old 07-23-2007   #2 (permalink)
RichS


 
 

RE: redirecting standar output when using [System.Diagnostics.Process]

Does this help

$nodes | foreach{ping "$_" | out-file "$_.log" }

--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"freddy chavez" wrote:

> Hello all. I want to execute a command against a bunch of IP nodes (servers,
> routers) in PARALLEL (not one after another). I demonstrate my case using
> PING, but it could be another tool.
>
> The following code works ok:
>
> $nodes="server1", "server2", "router1" #... a lot of nodes
> $nodes | foreach {[System.Diagnostics.Process]::Start("ping.exe","$_") }
>
> Now, i need to log all the responses to a unique file for every node, so I
> try:
>
> $nodes | foreach {[System.Diagnostics.Process]::Start("ping.exe","$_ >
> $_.log 2>&1") }
>
> But it's not working. The problem, i think, is the redirection of the
> standard output and standard error.
> Thanks for your help.
>
> Regards,
> Freddy Chavez.
>
>
>

My System SpecsSystem Spec
Old 07-23-2007   #3 (permalink)
Keith Hill


 
 

Re: redirecting standar output when using [System.Diagnostics.Process]::Start

"freddy chavez" <freddychavez22@hotmail.com> wrote in message
news:#WG2kxVzHHA.748@TK2MSFTNGP04.phx.gbl...
> Hello all. I want to execute a command against a bunch of IP nodes
> (servers, routers) in PARALLEL (not one after another). I demonstrate my
> case using PING, but it could be another tool.
>
> The following code works ok:
>
> $nodes="server1", "server2", "router1" #... a lot of nodes
> $nodes | foreach {[System.Diagnostics.Process]::Start("ping.exe","$_") }
>
> Now, i need to log all the responses to a unique file for every node, so I
> try:
>
> $nodes | foreach {[System.Diagnostics.Process]::Start("ping.exe","$_ >
> $_.log 2>&1") }
>
> But it's not working. The problem, i think, is the redirection of the
> standard output and standard error.
> Thanks for your help.


Redirection via ">" is a feature of a shell (CMD, PowerShell) and not
ping.exe. Try this:

$nodes | foreach {[System.Diagnostics.Process]::Start("cmd.exe","/c ping.exe
$_ > ${_}.log 2>&1") }

--
Keith


My System SpecsSystem Spec
Old 07-24-2007   #4 (permalink)
freddy chavez


 
 

Re: redirecting standar output when using [System.Diagnostics.Process]::Start

> $nodes | foreach {[System.Diagnostics.Process]::Start("cmd.exe","/c
> ping.exe $_ > ${_}.log 2>&1") }
>
> Keith


this was exactly what i've been looking for... thanks a lot Keith !!!


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
[diagnostics.process]::start("exe") PowerShell
Question about [System.Diagnostics.Process]::Start() PowerShell
Wrap command shell in System.Diagnostics.Process PowerShell
Using ProcessStartInfo with [System.Diagnostics.Process]::Start PowerShell
Stupid [Diagnostics.Process]::Start("..") tricks PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46