Foxtable(狐表)用户栏目专家坐堂 → 如何调用全局代码中的过程


  共有4266人关注过本帖树形打印复制链接

主题:如何调用全局代码中的过程

帅哥哟,离线,有人找我吗?
zhenghangbo
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:4612 威望:0 精华:0 注册:2018/2/7 14:30:00
如何调用全局代码中的过程  发帖心情 Post By:2021/6/27 11:04:00 [显示全部帖子]

全局代码里面定义了一个sendCommand函数, 一个WriteStream过程,一个ReadStream函数。代码没问题,要引入Renci.SshNet.dll。(连接linux打指令用的)
怎么在外面执行WriteStream过程中的writer.WriteLine(cmd)。?

Public Function sendCommand(ByVal customCMD As String) As StringBuilder
Dim connInfo As New Renci.SshNet.PasswordConnectionInfo(IP,账户, 密码)
Dim sshClient As New Renci.SshNet.SshClient(connInfo)
sshClient.Connect()    '启动连接
Dim stream = sshclient.CreateShellStream("customCommand", 80, 24, 800, 600, 1024)
Dim answer As StringBuilder
Dim reader = New IO.StreamReader(CType(stream,System.IO.stream))
Dim writer = New IO.StreamWriter(CType(stream,System.IO.stream))
writer.AutoFlush = True
WriteStream(customCMD, writer, stream)
answer =ReadStream(reader)
Return answer
End Function
 Sub  WriteStream(ByVal cmd As String, ByVal writer As IO.StreamWriter, ByVal stream As Renci.SshNet.ShellStream)  
        writer.WriteLine(cmd)
        While stream.Length = 0
        Threading.Thread.Sleep(500)
    End While
End Sub
Function ReadStream(ByVal reader As  IO.StreamReader) As StringBuilder
        Dim result As StringBuilder = New StringBuilder()
        Dim line As String

        While (CSharpImpl.__Assign(line, reader.ReadLine())) IsNot Nothing
            result.AppendLine(line)
        End While

        Return result
    End Function
Public Class CSharpImpl
        <Obsolete("Please refactor calling code to use normal Visual Basic assignment")>
        Shared Function __Assign(Of T)(ByRef target As T, value As T) As T
            target = value
            Return value
        End Function
End Class
[此贴子已经被作者于2021/6/27 11:11:51编辑过]

 回到顶部