There are a few minor problems here.
1) There is a slight bug in that the script does a 1-second buffering of
data for each block of data it reads. Instead, it should do the 1-second
buffering only after it exhausts available data. This is what made you think
it didn't work, as it took so long.
## Read output from a remote host
function GetOutput
{
$outputBuffer = ""
$foundMore = $false
## Read all the data available from the stream, writing it to the
## output buffer when done.
do
{
## Allow data to buffer for a bit
start-sleep -m 1000
## Read what data is available
$foundmore = $false
while($stream.DataAvailable)
{
$read = $stream.Read($buffer, 0, 1024)
$outputBuffer += ($encoding.GetString($buffer, 0, $read))
$foundmore = $true
}
} while($foundmore)
$outputBuffer
}
2) The script works in a batch mode. You send it data, it reads all
available data, then it's your turn again. Because of that, it will buffer
up large responses before it returns them to you.
3) If a service returns a huge amount of data, the script tries to write all
of the output at once. That exhausts the capacity of the Windows console
buffer, so the fix is to split it and write it line-by-line:
## If we're in interactive mode, write the buffered
## output, and respond to input.
else
{
if($output)
{
foreach($line in $output.Split("`n"))
{
write-host $line
}
$SCRIPT

utput = ""
}
Thanks for pointing this out, I'll update the original post.
--
Lee Holmes [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"Marco Shaw" <marco@Znbnet.nb.ca> wrote in message
news:O1yK5ZgGHHA.1912@TK2MSFTNGP03.phx.gbl...
> http://www.leeholmes.com/blog/Script...owerShell.aspx
>
> Interesting entry...
>
> I can't seem to extend this to NNTP though.
>
> I think the proper PSH equivalent of [Return] is "`r"?
>
> I tried different combos without luck:
>
> PS C:\> $nntp=@"
>>> LIST
>>> `r`n
>>> QUIT
>>> `r`n
>>> "@
>>> <--Seems to just hang
> PS C:\> $nntp|.\connect-remote.ps1 news.microsoft.com 119
> PS C:\> $nntp=@"
>>> LIST
>>> `r
>>> QUIT
>>> `r
>>> "@
>>> <--Seems to just hang
> PS C:\> $nntp|.\connect-remote.ps1 news.microsoft.com 119
> PS C:\> $nntp=@"
>>> LIST
>>> QUIT
>>> "@
>>>
> PS C:\> $nntp|.\connect-remote.ps1 news.microsoft.com 119
> 200 NNTP Service 6.0.3790.1830 Version: 6.0.3790.1830 Posting Allowed
> 501 Syntax Error in Command
>
> Any ideas?
>