![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | Lee Holmes' blog: TCP in PSH 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? |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Lee Holmes' blog: TCP in PSH In message <O1yK5ZgGHHA.1912@TK2MSFTNGP03.phx.gbl>, Marco Shaw <marco@Znbnet.nb.ca> writes >Any ideas? I've re-created your problems here. The main idea I'd have suggested is "use telnet" ;-) However, I'm using Vista and there's no telnet client in Vista any more. Thomas -- Thomas Lee doctordns@gmail.com MVP - Admin Frameworks and Security |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Lee Holmes' blog: TCP in PSH > However, I'm using Vista and there's no telnet client in Vista any more. Maybe... http://www.leeholmes.com/blog/Replac...FromVista.aspx Read the comments all the way at the bottom... Version 1 of his TCP connect is also very good. It only has a 1024 byte buffer though, but one can easily fix that... |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Lee Holmes' blog: TCP in PSH TMK, telnet is not gone, it is just not installed by default. You can get it back: http://vista.beyondthemanual.com/200...lnet_back.html I have not tried it. -- William Stacey [C# MVP] "Thomas Lee" <tfl@psp.co.uk> wrote in message news:JoSuE3YkKCeFFANO@mail.psp.co.uk... | In message <O1yK5ZgGHHA.1912@TK2MSFTNGP03.phx.gbl>, Marco Shaw | <marco@Znbnet.nb.ca> writes | >Any ideas? | | I've re-created your problems here. | | The main idea I'd have suggested is "use telnet" ;-) | | However, I'm using Vista and there's no telnet client in Vista any more. | | Thomas | | -- | Thomas Lee | doctordns@gmail.com | MVP - Admin Frameworks and Security |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Lee Holmes' blog: TCP in PSH 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? > |
My System Specs![]() |
| | #6 (permalink) |
| Guest | 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 Specs![]() |
| | #7 (permalink) |
| Guest | Re: Lee Holmes' blog: TCP in PSH Hi Marco; If you want to use the script interactively, but also have it write the output to a file, this is what I would do: 1) Add an optional filename parameter to the script so that your script can know when the user (you) want to redirect into a file as well. You can use the way that the script handles the $inputObject parameter as an example of this. 2) In the part that writes the line to the host (write-host $line,) add a line below it that appends that line to a file as well (if the user specified a filename.) That way, you'll still get the visual feedback, but will have the contents also going into a file. -- 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:OV9er3mGHHA.3616@TK2MSFTNGP06.phx.gbl... > 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 Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Blog | Live Mail | |||
| PowerShell Blog | PowerShell | |||
| sherlock holmes the awakened | Vista Games | |||
| New book by Lee Holmes ("draft" available) | PowerShell | |||