@egagne, I see now that PowerShell is very similar. I, too, took notes from the same emails, and came up with a more .NET-ish solution. So it wouldn't be taken offline, I posted the whole thing (sample code, output, etc.) on my blog here.
To preserve space here, I will say that I created for my tests several functions, a few of which are:
So all you so is create a ShellStream, and pass it to one of the functions. That function will return only the text from the command. This was the hard part. Once I got it to work, it seemed nothing I tried would clear out the buffers-making all previous input/output part of the current output!
I write in lots of languages, but since everyone here discusses in C# (and the source is in C#), I thought I'd help out the VB.NET folks.
This project, and the DLL/library it creates, are really great. Since I don't know what kind of development help is needed, right now all I can do is pass on some working code for others to get over the difficulties that plagued me for about 20 hours!
Thanks again, folks, and let me know if there is any way I can contribute.
pat
:)
To preserve space here, I will say that I created for my tests several functions, a few of which are:
Function SendCommand(cmd As String, s As ShellStream) As String
Try
reader = New StreamReader(s)
writer = New StreamWriter(s)
writer.AutoFlush = True
writer.WriteLine(cmd)
While s.Length = 0
Thread.Sleep(500)
End While
Catch ex As Exception
Debug.WriteLine("SendCommand(" & cmd & ") caught exception: " & ex.ToString())
End Try
Return reader.ReadToEnd()
End Function
Function SendCommandW(cmd As String, s As ShellStream) As String
Try
reader = New StreamReader(s)
writer = New StreamWriter(s)
writer.AutoFlush = True
writer.Write(cmd)
While s.Length = 0
Thread.Sleep(500)
End While
Catch ex As Exception
Debug.WriteLine("SendCommandW(" & cmd & ") caught exception: " & ex.ToString())
End Try
Return reader.ReadToEnd()
End Function
On the blog I take the time to explain why there is more than one SendCommand(). You can probably tell from the above why-especially if you have had to work with Cisco IOS for any length of time. So all you so is create a ShellStream, and pass it to one of the functions. That function will return only the text from the command. This was the hard part. Once I got it to work, it seemed nothing I tried would clear out the buffers-making all previous input/output part of the current output!
I write in lots of languages, but since everyone here discusses in C# (and the source is in C#), I thought I'd help out the VB.NET folks.
This project, and the DLL/library it creates, are really great. Since I don't know what kind of development help is needed, right now all I can do is pass on some working code for others to get over the difficulties that plagued me for about 20 hours!
Thanks again, folks, and let me know if there is any way I can contribute.
pat
:)