View Single Post
Old 12-07-2006   #6 (permalink)
Marco Shaw


 
 

Re: Lee Holmes' blog: TCP in PSH

Now, instead of outputting to the host, I'd like to ouput to a string or
file for later processing.

With version 1, this seemed more obvious to accomplish:

Change this part:
while($stream.DataAvailable)
{
$read = $stream.Read($buffer, 0, 4096)
write-host -n ($encoding.GetString($buffer, 0, $read))
}

To something like:
while($stream.DataAvailable)
{
$read = $stream.Read($buffer, 0, 4096)
write-output ($encoding.GetString($buffer, 0,
$read))|out-file -append -encoding ascii -filepath some_log_file
}

I'm sure my problem with my test though is that the buffer was just too
small. I did get output written to some_log_file! But the problem also
occured that I didn't have any feedback as to when I could enter my 2nd
command.

I'm assuming that I could just use this to output to a string, but haven't
tried it:
while($stream.DataAvailable)
{
$read = $stream.Read($buffer, 0, 4096)
$out_data+=($encoding.GetString($buffer, 0, $read))
}


With version 2 though, I'd like to use your scripting functionality, but I'm
not experienced enough in PSH to figure out what's going on, and determine
where I need to send the output to a string or file.

Can you help me?

Marco


My System SpecsSystem Spec