做......直到-loop不退出

问题描述 投票:-1回答:1
local $results, $h, $PID, $BlueStacks_Path

$BlueStacks_Path = @ProgramFilesDir & "\BlueStacks\"
$BlueStacks_Path = StringReplace($BlueStacks_Path, "\\", "\")
$h = Run($BlueStacks_Path & "hd-Adb connect localhost","","",$STDIO_INHERIT_PARENT)
sleep(1000)
$PID = run($BlueStacks_Path & "HD-Frontend.exe Testing")
WinGetProcess($PID)
sleep(1000)
Do
    $result = run($BlueStacks_Path & "HD-Adb shell getprop sys.boot_completed", "", "", BitOR($STDIN_CHILD, $STDERR_MERGED))
    $Read = StdoutRead($result)
    ConsoleWrite("$Read : " & $Read & @CRLF)
    sleep(1000)
until $result = 1

我想知道为什么在检查BlueStacks是否打开时我得到一个无限循环。

如果我以命令行为基础,一切正常。但是当我把它放在AutoIt中它只是无限循环,因为ConsoleWrite()显示$Read返回一个空白而不是1device not loaded

我究竟做错了什么?

loops autoit bluestacks
1个回答
0
投票

我究竟做错了什么?

根据Documentation - Function Reference - Run()

回报价值 成功:已启动的流程的PID。 失败:0并将@error标志设置为非零。

PID不太可能是1。如果任何非0值应退出循环(根据Documentation - Language Reference - Operators),则将最后一行更改为以下任一项:

  • Until $result
  • Until $result > 0
  • Until Not ($result = 0)

或者使用While...WEnd -loop;例:

Global Const $g_sFile = 'notepad.exe'
Global       $g_iPID  = 0

While Not $g_iPID

    $g_iPID = Run($g_sFile)

WEnd

但是,Run()失败的大多数原因都无法通过简单地重复调用来解决。

如果我以命令行为基础,一切正常。

从(个别)命令行参数返回STD输出的简单方法:

#include <AutoItConstants.au3>

Global Const $g_iDelay = 250
Global Const $g_sCom   = @ComSpec & ' /c '
Global Const $g_aCmd   = [ _
                         'help', _
                         'dir/w', _
                         'ping localhost' _
                         ]

Global       $g_iPID   = 0
Global       $g_sSTD   = ''

For $i1 = 0 To UBound($g_aCmd) - 1

    $g_iPID = Run($g_sCom & $g_aCmd[$i1], '', @SW_HIDE, $STDERR_MERGED)

    While ProcessExists($g_iPID)

        Sleep($g_iDelay)

    WEnd

    $g_sSTD = StdoutRead($g_iPID)
    ConsoleWrite($g_sSTD & @CRLF)

Next

Related

© www.soinside.com 2019 - 2024. All rights reserved.