找回密码
 加入
搜索
楼主: xiehuahere

[网络通信] 【已解决】如何通过 TCPSend() 发送 ctrl+c 给远程终端

 火.. [复制链接]
 楼主| 发表于 2011-3-9 15:05:20 | 显示全部楼层
版主你好,
现在我首先要解决的问题是,按"Execute”按钮远程执行脚本,在脚本执行过程中,按其他按钮没响应。
为什么OnEventMode会有这个问题呢?
不是很明白啊。
发表于 2011-3-9 15:21:57 | 显示全部楼层
你将server的地址设置正确后应该不会出现你说的问题
 楼主| 发表于 2011-3-10 12:04:04 | 显示全部楼层
哦,是吗?
那用一个短一点的小例子来看这个问题吧:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <GuiConstantsEx.au3>
Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ###
$Form1 = GUICreate("Form1", 252, 327, 192, 124, $WS_CAPTION)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 233, 257, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetData(-1, "This is the default text.")
$Button1 = GUICtrlCreateButton("Start", 16, 280, 113, 33)
GUICtrlSetOnEvent(-1, "FillEvent")
$Button2 = GUICtrlCreateButton("Exit", 168, 280, 65, 33)
GUICtrlSetOnEvent(-1, "ExitEvent")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        Sleep(10)
WEnd

Func FillEvent()
        GUICtrlSetState($Button1, $GUI_DISABLE)

        GUICtrlSetData($Edit1, "")
        $i = 0
        While($i < 20)
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "我看你怎么退出 ;-)")
                $i += 1
                Sleep(1000)
        WEnd

        GUICtrlSetState($Button1, $GUI_ENABLE)
EndFunc   ;==>ConnectEvent

Func ExitEvent()
        Exit 0
EndFunc   ;==>ExitEvent
点“Start”后,点击"Exit"是没响应的。请CEO明辨。
发表于 2011-3-10 13:11:43 | 显示全部楼层
是可以退出的,无论你执行多少个死循环,循环体内sleep的时间不要超过100毫秒就可以了,当然是越小越好,不过在100MS后也是可以退出的,只是响应的时间要长而已.
 楼主| 发表于 2011-3-10 14:50:18 | 显示全部楼层
本帖最后由 xiehuahere 于 2011-3-10 14:51 编辑

可真的是退出不了。就是上面的代码,循环体改了一下:

     While 1
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "我看你怎么退出 ;-)")
                Sleep(80)
        WEnd
发表于 2011-3-10 15:44:01 | 显示全部楼层
好吧.
我再说具体点:
windows是一个消息机构
对于autoit而言.你18#的代码中,FillEvent()相当于是一个消息处理函数,要让GUI即时响应你的消息(或者说无延时),那么,FillEvent()的执行时间就不能超时100MS,具体可以参考GUIRegisterMsg.
也就是说,在消息处理函数中,你必须要有返回才能证明你对这一消息处理成功,否则GUI就不能再处理同步的消息请求.不知道这样说容易理解不?

评分

参与人数 1金钱 +11 收起 理由
xiehuahere + 11 授人以渔,诲人不倦。 费了这么多口水,给 ...

查看全部评分

 楼主| 发表于 2011-3-10 21:50:09 | 显示全部楼层
谢谢ceo的耐心指教!
同时,我看了官网下面这个帖子#12
http://www.autoitscript.com/foru ... ith-guioneventmode/
里面举的例子很典型。
我得认真去读一下相关内容。受教了~~
等我想明白,再回头来更新一下代码。
我也希望到时候"everything will be as clear as crystal"。
 楼主| 发表于 2011-3-10 22:36:17 | 显示全部楼层
本帖最后由 xiehuahere 于 2011-3-11 09:52 编辑

修改后的:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)

; Declare a flag
$fInterrupt = 0

#Region ### START Koda GUI section ###
$Form1 = GUICreate("Form1", 252, 327, 192, 124, $WS_CAPTION)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 233, 257, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetData(-1, "This is the default text.")
$Button1 = GUICtrlCreateButton("Start", 16, 280, 113, 33)
GUICtrlSetOnEvent(-1, "FillEvent")
$Button2 = GUICtrlCreateButton("Exit", 168, 280, 65, 33)
GUICtrlSetOnEvent(-1, "ExitEvent")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; Intercept Windows command messages with out own handler
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

While 1
        Sleep(10)
WEnd

Func FillEvent()
        GUICtrlSetState($Button1, $GUI_DISABLE)

        GUICtrlSetData($Edit1, "")
        While 1
                _GUICtrlEdit_AppendText($Edit1, "看我成功退出吧, oh yeah~~" & @CRLF)
                If $fInterrupt <> 0 Then        Return
                Sleep(60)
        WEnd

        GUICtrlSetState($Button1, $GUI_ENABLE)
EndFunc   ;==>ConnectEvent

Func ExitEvent()
        Exit 0
EndFunc   ;==>ExitEvent

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    ; Button2 was pressed so set the flag
    If BitAND($wParam, 0x0000FFFF) =  $Button2 Then $fInterrupt = 1
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND
终于可以言归正题了。
现在ctrl+c不需要了,因为远程执行脚本的函数在返回前自己会关闭 TCP connection,这样通过远程用户登录得到运行的脚本也随着用户环境的退出而终止。
就先这样结贴吧。
发表于 2011-3-11 01:09:35 | 显示全部楼层
telnet没用过,来看看..
发表于 2011-10-20 11:36:22 | 显示全部楼层
ddddddddddddddddd抽空看看
发表于 2011-10-30 21:55:02 | 显示全部楼层
学习一下,多谢。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-16 16:05 , Processed in 0.076636 second(s), 17 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表