pdp320921 发表于 2011-4-1 19:38:24

从cmd中提取的变量输出出错

本帖最后由 pdp320921 于 2011-4-1 19:45 编辑

#include <Constants.au3>

Local $foo = Run(@ComSpec& " /c " & 'for /f "tokens=2" %i in (''arp -a^|findstr :'') do @echo %i', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

Local $line

While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:"&@error, $line)
Wend上述代码提取到了IP,可是我在最后用Send("{" & $line & "}")输出的结果怎么不是IP地址啊?

afan 发表于 2011-4-1 21:10:54

在循环里 $line 每次都被重新赋值了……

xxoojoeooxx 发表于 2011-4-1 21:32:54

本帖最后由 xxoojoeooxx 于 2011-4-1 21:33 编辑

Send是传送按键不是字串

要用

$Title=WinGetTitle("")
ControlSend($Title, "", "",$line )

pdp320921 发表于 2011-4-2 08:26:29

回复 2# afan

可是我send()放在循环里还是一样啊

pdp320921 发表于 2011-4-2 08:30:44

回复 3# xxoojoeooxx

Send是传送按键不是字串   

可我直接Send("192.168.0.1")却是ok的,怎么会不能发送字符串?

xxoojoeooxx 发表于 2011-4-2 15:43:14

本帖最后由 xxoojoeooxx 于 2011-4-2 15:45 编辑

回覆 5# pdp320921

应该说Send是传送你所给的按键顺序
像是汉字是不能用Send来处理的
{:face (396):}我上面的算多此一举了

pdp320921 发表于 2011-4-2 16:07:26

回复 6# xxoojoeooxx

可是我用
Local $foo = Run(@ComSpec& " /c " & 'for /f "tokens=2" %i in (''arp -a^|findstr :'') do @echo %i', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
ProcessWaitClose($foo)
$line = StdoutRead($foo)
Send("{"& $line &"}")
却得不到IP地址,又是为何?
用你上面的Local $foo = Run(@ComSpec& " /c " & 'for /f "tokens=2" %i in (''arp -a^|findstr :'') do @echo %i', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
ProcessWaitClose($foo)
$line = StdoutRead($foo)
;Send("{"& $line &"}")
$Title=WinGetTitle("")
ControlSend($Title, "", "",$line )
却是OK的,还有我感觉ControlSend命令运行结束后好像会自动切换到下个“窗口上键盘焦点所在的控件上”,不知为何?

xxoojoeooxx 发表于 2011-4-2 16:53:52

回复 7# pdp320921 Send($line)这样就好了不用加{}

pdp320921 发表于 2011-4-2 17:07:17

回复 8# xxoojoeooxx

send()发送变量可以直接这样?

不是Send("{"& $line &"}")?

xxoojoeooxx 发表于 2011-4-2 18:22:31

回复 9# pdp320921


   去看send的说明吧
页: [1]
查看完整版本: 从cmd中提取的变量输出出错