找回密码
 加入
搜索
查看: 3481|回复: 2

$STDOUT_CHILD 和 StdoutRead 为何物?

[复制链接]
发表于 2009-8-22 08:36:42 | 显示全部楼层 |阅读模式
#include <Constants.au3>
Opt("MustDeclareVars",1)
_test()
Func _test()
Local $foo,$line,$lines
$foo = Run(@ComSpec & " /c systeminfo", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
$lines = ""
While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
     $lines &= $line
Wend
MsgBox(0,"test",$lines)
EndFunc
$STDOUT_CHILD 和 StdoutRead 为何物?
不明白这变量和函数是什么.有没有人教下.
Run ( "文件名" [, "工作目录" [, 标志]] )
为什么上面的脚本在标专后面还加了个$STDOUT_CHIld
还有如果我要查Constants.au3要怎么用要怎么查啊.!!!!
发表于 2009-8-22 09:44:58 | 显示全部楼层
($STDOUT_CHILD) = 提供一个句柄到子 STDOUT 流.


函数参考
StdoutRead
--------------------------------------------------------------------------------

Reads from the STDOUT stream of a previously run child process.


StdoutRead ( process_id[, peek = false[, binary = false]] )




参数

process_id The process ID of a child process, as returned by a previous call to Run.
peek [optional] If true the function does not remove the read characters from the stream.
binary [optional] If true the function reads the data as binary instead of text (default is text).



返回值

Success: Returns the data read. @extended contains the number of bytes read.
Failure: Sets @error to non-zero if EOF is reached, STDOUT was not redirected for the process or other error.



注意/说明

StdoutRead reads from the console standard output stream of a child process, which is normally used by console applications to write to the screen. During the call to Run for the child process you wish to read from the STD I/O parameter must have included the value of $STDOUT_CHILD (2) for this function to work properly (see the Run function).
StdoutRead does not block, it will return immediately. In order to get all data, it must be called in a loop.
Peeking on the stream does not remove the data from the buffer, however, it does return the available data as normal.
By default, data is returned in text format. By using the binary option, the data will be returned in binary format.




相关

StderrRead, StdinWrite, StdioClose, Run, RunAs


示例/演示


; Demonstrates StdoutRead()
#include <Constants.au3>

Local $foo = Run(@ComSpec & " /c dir foo.bar", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

While 1
    $line = StderrRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDERR read:", $line)
Wend

MsgBox(0, "Debug", "Exiting...")
发表于 2009-8-22 11:13:10 | 显示全部楼层
你用的中文帮助文件版本过低,请下载新版,或对照英文原版帮助文件。
Run ( "filename" [, "workingdir" [, show_flag[, opt_flag ]]] )
opt_flag 是一个标志位,供脚本本身和它所调用的另一个程序之间进行交互。当值包含$STDOUT_CHILD时,它将返回子程序的标准输出流,通常我们用来获取DOS程序的命令行回显。StdoutRead函数的作用就是从子程序PID中实时读取返回流数据。
#include <Constants.au3> 用于定义一些常用常量。如果你需要知道这些常量代表的具体值,可以打开au3安装文件夹下Include里的对应文件查看。#include命令的参数部分说明,当其后的文件名使用尖括号<>,au3将在Include库文件夹里读取,就是上面所指文件夹。

评分

参与人数 1贡献 +3 收起 理由
afan + 3

查看全部评分

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

本版积分规则

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

GMT+8, 2024-12-22 22:56 , Processed in 0.089736 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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