我现在的需要是:在我的程序里加入Telnet,但是捕捉不到它的输入输出,怎么办?
5 个解决方案
#1
先贴你的代码
#2
代码我贴在了http://topic.csdn.net/u/20080724/10/5a153dbf-9fc9-400c-912d-3441a4f11e05.html
9楼
帮忙看一下,谢谢!
9楼
帮忙看一下,谢谢!
#3
Dim p As New Process
Dim strRet As String
p.StartInfo.FileName = "cmd.exe"
p.StartInfo.Arguments = "/C " & YourCommand 'Telnet
'关闭Shell的使用
p.StartInfo.UseShellExecute = False
'重定向标准输入
p.StartInfo.RedirectStandardInput = True
'重定向标准输出
p.StartInfo.RedirectStandardOutput = True
'重定向错误输出
p.StartInfo.RedirectStandardError = True
'设置不显示窗口
p.StartInfo.CreateNoWindow = True
p.Start()
strRet = p.StandardOutput.ReadToEnd
p.WaitForExit()
Return strRet
#4
楼上的不行,这个代码我也试过,对于cmd是可行的,但运行telnet时就不行了。不知为什么。
#5
没试过telnet,你telnet指令带上参数试试。
Public Function CmdExcute(ByVal ExcuteCommand As String) As String
Dim sReturn As String
Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process
Dim bOk As Boolean
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.Arguments = "/c " + ExcuteCommand
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.StartInfo.RedirectStandardError = True
myProcess.StartInfo.CreateNoWindow = True
bOk = myProcess.Start()
sReturn = ""
If bOk Then
sReturn = myProcess.StandardError.ReadToEnd()
Else
sReturn = "执行【 " & ExcuteCommand & "】失败"
End If
myProcess.WaitForExit()
myProcess.Close()
myProcess.Dispose()
Return sReturn
End Function
#1
先贴你的代码
#2
代码我贴在了http://topic.csdn.net/u/20080724/10/5a153dbf-9fc9-400c-912d-3441a4f11e05.html
9楼
帮忙看一下,谢谢!
9楼
帮忙看一下,谢谢!
#3
Dim p As New Process
Dim strRet As String
p.StartInfo.FileName = "cmd.exe"
p.StartInfo.Arguments = "/C " & YourCommand 'Telnet
'关闭Shell的使用
p.StartInfo.UseShellExecute = False
'重定向标准输入
p.StartInfo.RedirectStandardInput = True
'重定向标准输出
p.StartInfo.RedirectStandardOutput = True
'重定向错误输出
p.StartInfo.RedirectStandardError = True
'设置不显示窗口
p.StartInfo.CreateNoWindow = True
p.Start()
strRet = p.StandardOutput.ReadToEnd
p.WaitForExit()
Return strRet
#4
楼上的不行,这个代码我也试过,对于cmd是可行的,但运行telnet时就不行了。不知为什么。
#5
没试过telnet,你telnet指令带上参数试试。
Public Function CmdExcute(ByVal ExcuteCommand As String) As String
Dim sReturn As String
Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process
Dim bOk As Boolean
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.Arguments = "/c " + ExcuteCommand
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.StartInfo.RedirectStandardError = True
myProcess.StartInfo.CreateNoWindow = True
bOk = myProcess.Start()
sReturn = ""
If bOk Then
sReturn = myProcess.StandardError.ReadToEnd()
Else
sReturn = "执行【 " & ExcuteCommand & "】失败"
End If
myProcess.WaitForExit()
myProcess.Close()
myProcess.Dispose()
Return sReturn
End Function