以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 如何调用全局代码中的过程 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=169705) |
-- 作者:zhenghangbo -- 发布时间: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编辑过]
|
-- 作者:有点蓝 -- 发布时间:2021/6/27 20:50:00 -- 只能执行定义好的某个函数,没有办法执行函数里的某一句代码的 |