本帖最后由 xiehuahere 于 2011-2-22 13:20 编辑
从 Windows telnet 到 Linux,建立 主机 与 设备 的通信,这是典型的嵌入式测试环境。
我的问题代表了一类人的需求。
http://www.autoitscript.com/foru ... _590023#entry590023
这个4楼的帖子具有相当的参考价值。又是一种方法。稍作修改和封装,如下:;Using native socket connection to simulates a TELNET connection to communicate with Linux machine for sending commands and receiving info from it
$port = 23
$user = "root"
$passwd = "xxxxxx"
TCPStartup()
$socket = TCPConnect($host, $port)
If $socket = -1 Then
MsgBox(48, "Error", "Connection fail!")
Exit
EndIf
Sleep(300)
$ack = TCPRecv($socket, 150)
If StringInStr($ack, "login") > 0 Then
TCPSend($socket, $user & @CRLF)
Sleep(500)
TCPSend($socket, $passwd & @CRLF)
Else
MsgBox(48, "Error", "Cannot connect")
Exit
EndIf
wait_cmd_prompt($socket)
TCPSend($socket, $cmd1 & @CRLF)
wait_cmd_prompt($socket)
TCPSend($socket, $cmd2 & @CRLF)
wait_cmd_prompt($socket)
TCPCloseSocket($socket)
TCPShutdown()
;================================================================================================
; Function Definition
;================================================================================================
;Wait for desired command prompt character "#" before sending.
Func wait_cmd_prompt($sk)
Local $ack
Do
$ack = StringStripWS(TCPRecv($sk, 300), 2)
Sleep(300)
;MsgBox(0,"",$ack)
Until StringRight($ack, 1) = "#"
;MsgBox(0,"","out of loop")
EndFunc
不过,我一楼发的问题还没得到解决。
运行设备端(Linux环境)的脚本(shell脚本)远比远程命令控制来得可靠,因为这样Linux的一些环境变量是可继承的。
继续研究中。 |