【问题标题】:Adb sleep function working on adb but not in a .sh fileadb sleep 函数在 adb 上工作,但不在 .sh 文件中
【发布时间】:2017-12-30 12:11:07
【问题描述】:

我正在尝试制作一个简单的“点击并等待”脚本,以通过 adb 在我的 Android 设备上运行。

在 Powershell 上使用命令 ./adb shell 打开 adb 有效,运行 input tap 300 300 有效,运行 sleep 1 会休眠一秒钟。

但是,如果我使用 Powershell 命令 ./adb shell "sh /sdcard/Download/test.sh" 运行 test.sh 脚本,点击部分仍然有效,但 sleep 调用给了我这个:'sdcard/Download/MIOPROGRAMMA.sh[2]: sleep: syntax error: Invalid argument '1

知道为什么会这样吗?

【问题讨论】:

  • 你应该给我们看一些代码.. sleep call 可能是正确的抱怨

标签: android bash shell powershell


【解决方案1】:

只需在int 后面加上;,即:

input tap 250 250
sleep 3;
input tap 350 250
sleep 3;
input tap 450 250
sleep 3;
input tap 550 250
sleep 3;
input tap 650 250
sleep 3;

【讨论】:

    【解决方案2】:

    为什么不使用 powershell 的 Start-Sleep cmdlet 呢?在 powershell 脚本中包含所有逻辑。

    $sendTapCmd = "adb shell `"input tap 250 250`" "
    $numberOfTaps = 5  
    
    for ($i=0;$i -lt $numberOfTaps;$i++) {
        $output = Invoke-Expression $sendTapCmd
        Start-Sleep -Milliseconds 3
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多