Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (C) Alexander B. Prokopyev, 2014, aulix.com
- Module Test
- Function Run()
- AddHandler MainModule.Bash.DataReceived, AddressOf Test.Bash_DataReceived
- Bash.ExecAsyncCommand("dstat 1 5; echo stop$[1+2]", "stop3")
- End Function
- Private Sub Bash_DataReceived(ByVal S As String)
- Console.WriteLine(S)
- End Sub
- End Module
- Public Class AutoPenguin
- Public WithEvents Shell As Renci.SshNet.ShellStream
- Public SR As IO.StreamReader
- Public SW As IO.StreamWriter
- Public Function OpenShell()
- If SSHClient.IsConnected Then
- 'Dim sshOutput As New Text.StringBuilder
- Try
- Shell = SSHClient.CreateShellStream("dumb", 80, 24, 800, 600, 1024)
- SR = New IO.StreamReader(Shell)
- SW = New IO.StreamWriter(Shell)
- SW.AutoFlush = True
- Catch ex As Exception
- Console.WriteLine(ex.ToString)
- End Try
- End If
- End Function
- Public Function F1(ByVal S As String)
- End Function
- Public StopOnText As String
- Public AR As IAsyncResult
- Function ExecAsyncCommand(ByVal CmdText As String, ByVal StopOnText_ As String)
- OpenShell()
- Shell.WriteLine(CmdText)
- StopOnText = StopOnText_
- AR = Shell.BeginExpect(New Renci.SshNet.ExpectAction(StopOnText, AddressOf F1))
- AR.AsyncWaitHandle.WaitOne()
- 'Shell.Expect(StopOnText)
- End Function
- Public Event DataReceived(ByVal S As String)
- Private Sub Shell_DataReceived(ByVal sender As Object, ByVal e As Renci.SshNet.Common.ShellDataEventArgs) Handles Shell.DataReceived
- Dim S As String
- 'While Not Shell.DataAvailable
- ' 'Shell.WaitHandle.WaitOne()
- 'End While
- If Shell.DataAvailable Then
- S = Shell.Read()
- Debug.Print("Shell_DataReceived: " & S)
- 'RaiseEvent DataReceived(S)
- If InStr(S, StopOnText, CompareMethod.Text) > 0 Then
- 'Dim AR = New Renci.SshNet.ExpectAsyncResult
- AR.AsyncWaitHandle.Close()
- Shell.EndExpect(AR)
- 'Shell.Close()
- End If
- End If
- End Sub
- Public Event ErrorOccurred(ByVal e As Renci.SshNet.Common.ExceptionEventArgs)
- Private Sub ShStream_ErrorOccurred(ByVal sender As Object, ByVal e As Renci.SshNet.Common.ExceptionEventArgs) Handles Shell.ErrorOccurred
- Debug.Print("ErrorOccurred: " & e.ToString)
- RaiseEvent ErrorOccurred(e)
- End Sub
- end class
Advertisement
Add Comment
Please, Sign In to add comment