Response to Marc Clifton - Part 2
Marc,
...continuing on, I think I beat your #1 question to death... Let's keep things moving... :)
The next question I think I know the answer to:
2. Using the following code, why does "ls" work but "cd [to some folder]" doesn't?
Simple Answer: Because you were not creating an interactive shell. The end of the first command signaled the end of the session, and the (internal) shellstream disconnected. If you cd'd first, the opposite would happen (I couldn't see your ls or cd commands in your paste, BTW)...
This, referring to my Part 1 response, is the 2nd way I know how to interact with servers. I just figured out my first rough draft of how this woks yesterday via this post. I won't re-paste the code from that post, but I think I explained it pretty well for someone not used to using all of this... :)
_3. How do I display the typical *nix prompt? (For example, I'm connecting to a BeagleBone Black with Debian installed, so no, I don't care if you see Debian's default username and password in the code below.)_
Does that by chance use a BeagleBoard? My last company was putting their Linux server/appliance on one of those bad boys... Great developers, by the way, nice folks.
4. This looks like a great library, and I wouldn't mind actually writing a Code Project article or two showing how to use it, but I'm stuck on some very basic stuff!
How do you even write a CP article? I looked around and couldn't figure out how to even submit one for review! :)
OK. So between these 2 methods, which both work, let the community know if you aren't able to make any progress! :)
Thanks!
pat
:)
P.S. This is most of the meaningful bits of SendCommand, ignoring all the reconnect, retry, are we enable? logic...:
note: SleepMS can be adjusted dynamically, as well, by the program to suit the nature of the network, command, etc. Hard-coding timeouts based on my zippy test machines & LAN never works out in the real word! :)
A lot of hard hours of hair pulling in these 2 parts, but I'm glad to give back... :)
Marc,
...continuing on, I think I beat your #1 question to death... Let's keep things moving... :)
The next question I think I know the answer to:
2. Using the following code, why does "ls" work but "cd [to some folder]" doesn't?
Simple Answer: Because you were not creating an interactive shell. The end of the first command signaled the end of the session, and the (internal) shellstream disconnected. If you cd'd first, the opposite would happen (I couldn't see your ls or cd commands in your paste, BTW)...
This, referring to my Part 1 response, is the 2nd way I know how to interact with servers. I just figured out my first rough draft of how this woks yesterday via this post. I won't re-paste the code from that post, but I think I explained it pretty well for someone not used to using all of this... :)
_3. How do I display the typical *nix prompt? (For example, I'm connecting to a BeagleBone Black with Debian installed, so no, I don't care if you see Debian's default username and password in the code below.)_
Does that by chance use a BeagleBoard? My last company was putting their Linux server/appliance on one of those bad boys... Great developers, by the way, nice folks.
4. This looks like a great library, and I wouldn't mind actually writing a Code Project article or two showing how to use it, but I'm stuck on some very basic stuff!
How do you even write a CP article? I looked around and couldn't figure out how to even submit one for review! :)
OK. So between these 2 methods, which both work, let the community know if you aren't able to make any progress! :)
Thanks!
pat
:)
P.S. This is most of the meaningful bits of SendCommand, ignoring all the reconnect, retry, are we enable? logic...:
note: SleepMS can be adjusted dynamically, as well, by the program to suit the nature of the network, command, etc. Hard-coding timeouts based on my zippy test machines & LAN never works out in the real word! :)
[...]
'========================================================
'
' reader:
'
reader = New StreamReader(Me.ss)
'
' writer:
'
writer = New StreamWriter(Me.ss)
' writer.Flush() ' causing our Client to disconnect, for some reason...(?)
'
writer.AutoFlush = True
'
result = New StringBuilder(System.String.Empty)
'
Select Case LCase(eol)
Case ""
log.Debug("SendCommand() doing WriteLine(" & cmd & ")")
writer.WriteLine(cmd)
Case "w"
log.Debug("SendCommand() doing Write(" & cmd & ")")
writer.Write(cmd)
Case "cr"
log.Debug("SendCommand() doing Write(" & cmd & " & vbCr)")
writer.Write(cmd & vbCr)
Case "lf"
log.Debug("SendCommand() doing Write(" & cmd & " & vbLF)")
writer.Write(cmd & vbLf)
Case Else
log.Error("SendCommand(" & cmd & ") unknown eol: [" & eol & "]")
End Select
'
log.Debug("SendCommand() sleeping for " & sleepMs & " milliseconds (after write, before listen)")
Thread.Sleep(sleepMs)
'
Dim waitCycles As Integer = 5
While (Me.ss.DataAvailable = False) And (Me.ss.Length = 0) And (waitCycles > 0)
log.Debug("[" & waitCycles & "] ss.Length: " & Me.ss.Length)
Thread.Sleep(sleepMs)
waitCycles -= 1
End While
result.AppendLine(reader.ReadToEnd())
[...]
...you get the idea!A lot of hard hours of hair pulling in these 2 parts, but I'm glad to give back... :)