找回密码
 加入
搜索
查看: 2078|回复: 8

[AU3基础] 【已解决】有没有办法向隐藏的cmd发送ctrl + c 终止ping命令呢??

  [复制链接]
发表于 2017-2-16 11:30:30 | 显示全部楼层 |阅读模式
本帖最后由 229989799 于 2017-2-17 21:37 编辑

ping命令加了参数-t一直ping回显到编辑框里面,如何暂停呢?
$foo = Run("ping www.baidu.com -t", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
有没有办法向隐藏的cmd发送ctrl + c 终止ping命令呢??






解决办法在 9# 。。新手福音啊
发表于 2017-2-16 14:44:40 | 显示全部楼层
可以选择挂起这个进程
发表于 2017-2-16 15:34:13 | 显示全部楼层
回复 1# 229989799


    話說回來  我比較好奇的是......

PING 加了 -t   先別管 AU3   

單純以  DOS 下 來說   如何在 CMD 底下可以暫停???

印象中 連暫停都沒辦法吧.....  只能按 CTRL+C 中斷吧
 楼主| 发表于 2017-2-16 15:56:50 | 显示全部楼层
回复 3# kk_lee69


   大神理解正确。。有没有办法向隐藏的cmd发送ctrl + c 终止ping命令呢??
 楼主| 发表于 2017-2-16 17:09:52 | 显示全部楼层
有没有办法向隐藏的cmd发送ctrl + c 终止ping命令呢??
发表于 2017-2-16 19:37:47 | 显示全部楼层
用ProcessClose关闭进程就行
 楼主| 发表于 2017-2-16 20:02:29 | 显示全部楼层
回复 6# h20040606


    你测试一下看看能不能关闭ping进程? 我反正试了关不了的
发表于 2017-2-17 18:32:16 | 显示全部楼层
回复 7# 229989799


au3 单线程的  你在 回显时 简单 结束进程  没用

注册个热键函数就行
发表于 2017-2-17 21:30:07 | 显示全部楼层
回复 1# 229989799


    麻蛋 搞这没用的东西 浪费我几小时
#include <Constants.au3 >
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

ProcessClose("ping.exe")
ProcessClose("ping.exe")
Opt("GUIOnEventMode", 1)
HotKeySet("^c", "Close_Ping")

Global $main = GUICreate("测试窗口", 633, 451, 193, 125)
Global $myedit = GUICtrlCreateEdit("", 5, 32, 620, 200)
Global $Button1 = GUICtrlCreateButton("Ping回显", 8, 408, 617, 33, 0)

;GUISetOnEvent(-3, "gui")
GUICtrlSetOnEvent($Button1, "gui")
GUIRegisterMsg($WM_SYSCOMMAND, 'WM_SYSCOMMAND')

GUISetState(@SW_SHOW)

While 1
        Sleep(1)
        If GUICtrlGetState($Button1) = 144 Then GUICtrlSetState($Button1, 64)
WEnd

Func gui()
        Switch @GUI_CtrlId
                Case $Button1
                        Ping_test()
        EndSwitch
EndFunc

Func Ping_test()
        GUICtrlSetData($Button1, '正在Ping 再按停止 或按Ctrl+c停止')
        ;GUICtrlSetState($myedit,128)
        Local $foo, $line
        $foo = Run('ping -t 127.0.0.1', @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
        While 1
                Local $info = GUIGetCursorInfo($main)
                If $info[4] = $Button1 And $info[2] Then
                        GUICtrlSetData($Button1, 'Ping回显')
                        If GUICtrlGetState($Button1) = 80 Then GUICtrlSetState($Button1, 128)
                        Do
                                $info = GUIGetCursorInfo($main)
                        Until $info[2] = 0
                        Return
                EndIf

                Sleep(99)
                $line = StdoutRead($foo)
                If @error Then ExitLoop
                GUICtrlSetData($myedit, $line, -1)
        WEnd
EndFunc


Func Close_Ping()
        GUICtrlSetData($Button1, 'Ping回显')
        While ProcessExists('ping.exe')
                ProcessClose('ping.exe')
        WEnd
EndFunc

Func WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam)
        Switch $wParam
                Case 0xF060
                        Close_Ping()
                        Exit
        EndSwitch
EndFunc

评分

参与人数 1金钱 +30 收起 理由
229989799 + 30 辛苦,后人会崇拜你的。论坛这样的例子真的 ...

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-26 16:40 , Processed in 0.083519 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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