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
会返回一个空白而不是1
或device not loaded
。
我做错了什么?
答案 0 :(得分: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