找回密码
 加入
搜索
查看: 2292|回复: 11

问一个最最基础的控制台问题

  [复制链接]
发表于 2016-4-10 18:35:41 | 显示全部楼层 |阅读模式
看到控制台的列子都是些到SciTE里面   这个控制台能不能搬到自己写的界面上呢?
发表于 2016-4-10 21:28:54 | 显示全部楼层
当然可以,一样的使用
StdoutRead(进程 ID[, 取数 = false[, 二进制]])
StderrRead(子进程 ID[, 取数 = false[, 二进制 = false]])
 楼主| 发表于 2016-4-11 09:20:02 | 显示全部楼层
回复 2# afan


    A大  我看了帮助没怎么看明白。能举例指导一下吗?
发表于 2016-4-11 10:07:36 | 显示全部楼层
帮助的例子是最简单的,如果看不懂那就得加油了
#include <AutoItConstants.au3>

Local $sFilePath = @ScriptDir ; 搜索当前脚本目录.
Example($sFilePath)

Func Example($sFilePath); 递归显示目录的文件列表.

        Local $sFilter = "*.*" ; 搜索当前目录的所有文件. 关于有效的通配符列表,使用"通配符"搜索帮助文档.

        If Not StringInStr(FileGetAttrib($sFilePath), "D") Then
                Return SetError(1, 0, 0)
        EndIf
        $sFilePath = StringRegExpReplace($sFilePath, "[\\/]+\z", "") & ""

        Local $iPID = Run(@ComSpec & ' /C DIR "' & $sFilePath & $sFilter & '" /B /A-D /S', $sFilePath, @SW_HIDE, $STDOUT_CHILD)
        ProcessWaitClose($iPID)

        ; 读 Run() 返回 PID 的 Stdin 流. 也可以在 while 循环中完成. 参考 StderrRead() 示例.
        Local $sOutput = StdoutRead($iPID)
        MsgBox(0, "读取流显示到本程序", $sOutput)
EndFunc   ;==>Example
 楼主| 发表于 2016-4-11 10:30:58 | 显示全部楼层
回复 4# afan


好勒,下来好好研究一下。
 楼主| 发表于 2016-4-13 15:53:44 | 显示全部楼层
回复 4# afan
#include <AutoItConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Button1 = GUICtrlCreateButton("点击测试", 272, 96, 75, 25)
$Edit1 = GUICtrlCreateEdit("", 8, 200, 601, 137)
GUICtrlSetData(-1, "这里实现控制台显示")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        Local $sFilePath = @ScriptDir ; 搜索当前脚本目录.
                        Local $test = Example($sFilePath)
;~ MsgBox(0, "", $test)
;~ ConsoleWrite($test)
                        ControlSetText($Form1, "", $Edit1, $test)

        EndSwitch
WEnd

Func Example($sFilePath); 递归显示目录的文件列表.

        Local $sFilter = "*.*" ; 搜索当前目录的所有文件. 关于有效的通配符列表,使用"通配符"搜索帮助文档.

        If Not StringInStr(FileGetAttrib($sFilePath), "D") Then
                Return SetError(1, 0, 0)
        EndIf
        $sFilePath = StringRegExpReplace($sFilePath, "[\\/]+\z", "") & ""

        Local $iPID = Run(@ComSpec & ' /C DIR "' & $sFilePath & $sFilter & '" /B /A-D /S', $sFilePath, @SW_HIDE, $STDOUT_CHILD)
        ProcessWaitClose($iPID)

        ; 读 Run() 返回 PID 的 Stdin 流. 也可以在 while 循环中完成. 参考 StderrRead() 示例.
        Local $sOutput = StdoutRead($iPID)
        MsgBox(0, "读取流显示到本程序", $sOutput)
        Return $sOutput
EndFunc   ;==>Example
A大实在搞不懂这个控制台样式如何实现的,不是一行一行写入,不够装B的样子。能再说一下吗?
发表于 2016-4-13 16:36:21 | 显示全部楼层
回复 6# heroxianf


    带你装逼带你灰~
#include <AutoItConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Button1 = GUICtrlCreateButton("点击测试", 272, 96, 75, 25)
$Edit1 = GUICtrlCreateEdit("", 8, 200, 601, 137)
GUICtrlSetLimit(-1, 999999999)
$hEdit = GUICtrlGetHandle(-1)
GUICtrlSetData(-1, "这里实现控制台显示")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        Local $sFilePath = @ScriptDir ; 搜索当前脚本目录.
                        Example($sFilePath)
        EndSwitch
WEnd

Func Example($sFilePath); 递归显示目录的文件列表.
        Local $sFilter = "*.*" ; 搜索当前目录的所有文件. 关于有效的通配符列表,使用"通配符"搜索帮助文档.
        If Not StringInStr(FileGetAttrib($sFilePath), "D") Then Return SetError(1, 0, 0)
        $sFilePath = StringRegExpReplace($sFilePath, "[\\/]+\z", "") & ""
        Local $iPID = Run(@ComSpec & ' /C DIR "' & $sFilePath & $sFilter & '" /B /A-D /S', $sFilePath, @SW_HIDE, $STDOUT_CHILD)
;~         ProcessWaitClose($iPID)
        Local $sOutput = StdoutRead($iPID)
        Local $sOutput = ""
        While 1
                $sOutput = StdoutRead($iPID)
                If @error Then ExitLoop
                _GUICtrlEdit_AppendText($hEdit, $sOutput)
        WEnd
        While 1
                $sOutput = StderrRead($iPID)
                If @error Then ExitLoop
                _GUICtrlEdit_AppendText($hEdit, $sOutput)
        WEnd
EndFunc   ;==>Example
对于例子中的调用,速度一般很快,循环读取有时读到的流信息并不完整,因此只能是大概的流信息。
即便 SciTE 也是如此。
 楼主| 发表于 2016-4-13 16:56:19 | 显示全部楼层
回复 7# afan


    太感谢,下来好好看看!逼格有高了一点点~
 楼主| 发表于 2016-4-13 17:05:06 | 显示全部楼层
回复 7# afan

认真看完之后,自己发现需要的是这个函数,真是够傻X的。
_GUICtrlEdit_AppendText()
 楼主| 发表于 2016-4-13 17:39:24 | 显示全部楼层
回复 7# afan

A大 我发现网编辑框里写入一定量的内容 就不在写入了。是不是编辑框里的文本字数有想限制呢?
发表于 2016-4-13 17:44:59 | 显示全部楼层
回复  afan

A大 我发现网编辑框里写入一定量的内容 就不在写入了。是不是编辑框里的文本字数有想限制呢 ...
heroxianf 发表于 2016-4-13 17:39



    确定仔细看了代码?7#第11行
 楼主| 发表于 2016-4-13 17:52:59 | 显示全部楼层
回复 11# afan

   这下看到了,还是对函数不够了解啊~  谢谢A大了,装B够用了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-19 23:53 , Processed in 0.077485 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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