You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Robot Framework中执行adb命令?解决重启命令报错问题

解决Robot Framework中执行adb重启命令的FileNotFoundError问题

错误原因

你使用Run Process关键字时,错误地把完整命令adb -s AAA reboot作为单个参数传递。Process库会将这个完整字符串当作一个可执行文件的路径去查找,而系统中不存在名为adb -s AAA reboot的文件,因此抛出FileNotFoundError。

解决方法

1. 正确拆分命令与参数

Run Process要求将命令本身和每个参数分别作为独立参数传入,正确写法如下:

*** Settings ***
Library     AppiumLibrary
Library     Process

*** Test Cases ***
Openwatchapp
    ${reboot} =    Run Process    adb    -s    AAA    reboot

2. 确保adb在系统PATH中

如果执行后仍报错,检查adb是否已添加到系统环境变量PATH中:

  • Windows:确认Android SDK的platform-tools目录已加入系统PATH
  • Linux/macOS:确认adb所在路径已加入~/.bashrc或~/.zshrc的PATH配置中

若未添加PATH,可直接使用adb的完整路径,例如:

# Windows示例
${reboot} =    Run Process    C:\Android\Sdk\platform-tools\adb    -s    AAA    reboot

# Linux/macOS示例
${reboot} =    Run Process    /home/user/android-sdk/platform-tools/adb    -s    AAA    reboot

3. 可选:使用shell参数(适用于复杂命令场景)

如果需要通过系统shell执行命令,可添加shell=True参数(不推荐用于简单命令,避免安全风险):

${reboot} =    Run Process    adb -s AAA reboot    shell=True

内容的提问来源于stack exchange,提问作者user22747995

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 17:29:53