M8Test Help

启动应用

使用Adb Shell

  • 权限: Adb

  • 组件:

  • 说明: 通过Adb Shell执行启动应用操作

import com.m8test.script.GlobalVariables.* // 创建一个adb shell对象, 需要具有adb权限 val shell = _shells.newAdbShell(_maps.mapOf()) // 启动app的命令, 第一个参数为要启动的应用包名,例如 "com.tencent.mm"。第二个参数为启动应用所需的用户 ID。例如 "0" 代表主用户,"999" 代表应用分身或工作资料用户。第三个参数为目标显示器的 ID。例如 "0" 代表主显示器。如果此字符串为空,则命令中不会包含 --display 参数,应用将在默认显示器上启动。 val command = _shellCommands.launchApp("com.m8test.app.runtime", "0", "0")!! // 打印生成的命令 _console.log("启动app的命令", command) // 通过adb shell执行生成的命令, 第一个参数为命令字符串, 第二个参数为配置函数, 如果不需要可以传递一个空函数, 具体用法可参考文档 val r = shell.exec(command) {} if (r.isSuccess()) { // 输出执行结果, 通过getOutput()方法获取输出内容 _console.log("output", r.getOutput()) } else { // 输出错误信息, 如果没有错误则输出空字符串 _console.log("error", r.getStderr()) } // 下面是简化版 //shell.exec(_shellCommands.launchApp("com.m8test.app.runtime", "0", "0")!!) {}
// 创建一个adb shell对象, 需要具有adb权限 def shell = $shells.newAdbShell($maps.mapOf()) // 启动app的命令, 第一个参数为要启动的应用包名,例如 "com.tencent.mm"。第二个参数为启动应用所需的用户 ID。例如 "0" 代表主用户,"999" 代表应用分身或工作资料用户。第三个参数为目标显示器的 ID。例如 "0" 代表主显示器。如果此字符串为空,则命令中不会包含 --display 参数,应用将在默认显示器上启动。 def command = $shellCommands.launchApp("com.m8test.app.runtime", "0", "0"); // 打印生成的命令 $console.log("启动app的命令", command) // 通过adb shell执行生成的命令, 第一个参数为命令字符串, 第二个参数为配置函数, 如果不需要可以传递一个空函数, 具体用法可参考文档 def r = shell.exec(command) {} if (r.isSuccess()) { // 输出执行结果, 通过getOutput()方法获取输出内容 $console.log("output", r.getOutput()) } else { // 输出错误信息, 如果没有错误则输出空字符串 $console.log("error", r.getStderr()) } // 下面是简化版 //shell.exec($shellCommands.launchApp("com.m8test.app.runtime", "0", "0")) {}
import com.m8test.script.core.api.shell.Result; import com.m8test.script.core.api.shell.Shell; import kotlin.jvm.functions.Function1; import java.util.HashMap; import static com.m8test.script.GlobalVariables.*; // 创建一个adb shell对象, 需要具有adb权限 Shell shell = $shells.newAdbShell(new HashMap<String, String>()); // 启动app的命令, 第一个参数为要启动的应用包名,例如 "com.tencent.mm"。第二个参数为启动应用所需的用户 ID。例如 "0" 代表主用户,"999" 代表应用分身或工作资料用户。第三个参数为目标显示器的 ID。例如 "0" 代表主显示器。如果此字符串为空,则命令中不会包含 --display 参数,应用将在默认显示器上启动。 String command = $shellCommands.launchApp("com.m8test.app.runtime", "0", "0"); // 打印生成的命令 $console.log("启动app的命令", command); // 通过adb shell执行生成的命令, 第一个参数为命令字符串, 第二个参数为配置函数, 如果不需要可以传递一个空函数, 具体用法可参考文档 assert command != null; Result r = shell.exec(command, new Function1() { @Override public Object invoke(Object o) { return null; } }); if (r.isSuccess()) { // 输出执行结果, 通过getOutput()方法获取输出内容 $console.log("output", r.getOutput()); } else { // 输出错误信息, 如果没有错误则输出空字符串 $console.log("error", r.getStderr()); } // 下面是简化版 //shell.exec($shellCommands.launchApp("com.m8test.app.runtime", "0", "0"), new Function1() { // @Override // public Object invoke(Object o) { // return null; // } //});
// 创建一个adb shell对象, 需要具有adb权限 let shell = $shells.newAdbShell($maps.mapOf()) // 启动app的命令, 第一个参数为要启动的应用包名,例如 "com.tencent.mm"。第二个参数为启动应用所需的用户 ID。例如 "0" 代表主用户,"999" 代表应用分身或工作资料用户。第三个参数为目标显示器的 ID。例如 "0" 代表主显示器。如果此字符串为空,则命令中不会包含 --display 参数,应用将在默认显示器上启动。 let command = $shellCommands.launchApp("com.m8test.app.runtime", "0", "0"); // 打印生成的命令 $console.log("启动app的命令", command) // 通过adb shell执行生成的命令, 第一个参数为命令字符串, 第二个参数为配置函数, 如果不需要可以传递一个空函数, 具体用法可参考文档 let r = shell.exec(command, function (config) { }) if (r.isSuccess()) { // 输出执行结果, 通过getOutput()方法获取输出内容 $console.log("output", r.getOutput()) } else { // 输出错误信息, 如果没有错误则输出空字符串 $console.log("error", r.getStderr()) } // 下面是简化版 // shell.exec($shellCommands.launchApp("com.m8test.app.runtime", "0", "0"), function (config) { // })
-- 创建一个adb shell对象, 需要具有adb权限 local shell = _shells:newAdbShell(_maps:mapOf()) -- 启动app的命令, 第一个参数为要启动的应用包名,例如 "com.tencent.mm"。第二个参数为启动应用所需的用户 ID。例如 "0" 代表主用户,"999" 代表应用分身或工作资料用户。第三个参数为目标显示器的 ID。例如 "0" 代表主显示器。如果此字符串为空,则命令中不会包含 --display 参数,应用将在默认显示器上启动。 local command = _shellCommands:launchApp("com.m8test.app.runtime", "0", "0"); -- 打印生成的命令 _console:log("启动app的命令", command) -- 通过adb shell执行生成的命令, 第一个参数为命令字符串, 第二个参数为配置函数, 如果不需要可以传递一个空函数, 具体用法可参考文档 local r = shell:exec(command, function(config) end) if (r:isSuccess()) then -- 输出执行结果, 通过getOutput()方法获取输出内容 _console:log("output", r:getOutput()) else -- 输出错误信息, 如果没有错误则输出空字符串 _console:log("error", r:getStderr()) end -- 下面是简化版 --shell:exec(_shellCommands:launchApp("com.m8test.app.runtime", "0", "0"), function() end)
<?php /** @var m8test_java\com\m8test\script\core\api\console\Console $console */ global $console; /** @var m8test_java\com\m8test\script\core\api\shell\Shells $shells */ global $shells; /** @var m8test_java\com\m8test\script\core\api\shell\ShellCommands $shellCommands */ global $shellCommands; /** @var m8test_java\com\m8test\script\core\api\collections\Maps $maps */ global $maps; // 创建一个adb shell对象, 需要具有adb权限 $shell = $shells->newAdbShell($maps->mapOf()); // 启动app的命令, 第一个参数为要启动的应用包名,例如 "com.tencent.mm"。第二个参数为启动应用所需的用户 ID。例如 "0" 代表主用户,"999" 代表应用分身或工作资料用户。第三个参数为目标显示器的 ID。例如 "0" 代表主显示器。如果此字符串为空,则命令中不会包含 --display 参数,应用将在默认显示器上启动。 $command = $shellCommands->launchApp("com.m8test.app.runtime", "0", "0"); // 打印生成的命令 $console->log("启动app的命令", $command); // 通过adb shell执行生成的命令, 第一个参数为命令字符串, 第二个参数为配置函数, 如果不需要可以传递一个空函数, 具体用法可参考文档 $r = $shell->exec($command, function () { }); if ($r->isSuccess()) { // 输出执行结果, 通过getOutput()方法获取输出内容 $console->log("output", $r->getOutput()); } else { // 输出错误信息, 如果没有错误则输出空字符串 $console->log("error", $r->getStderr()); } // 下面是简化版 //$shell->exec($shellCommands->launchApp("com.m8test.app.runtime", "0", "0"), function () { //});
from m8test_java.com.m8test.script.GlobalVariables import _console from m8test_java.com.m8test.script.GlobalVariables import _maps from m8test_java.com.m8test.script.GlobalVariables import _shellCommands from m8test_java.com.m8test.script.GlobalVariables import _shells # 创建一个adb shell对象, 需要具有adb权限 shell = _shells.newAdbShell(_maps.mapOf()) # 启动app的命令, 第一个参数为要启动的应用包名,例如 "com.tencent.mm"。第二个参数为启动应用所需的用户 ID。例如 "0" 代表主用户,"999" 代表应用分身或工作资料用户。第三个参数为目标显示器的 ID。例如 "0" 代表主显示器。如果此字符串为空,则命令中不会包含 --display 参数,应用将在默认显示器上启动。 command = _shellCommands.launchApp("com.m8test.app.runtime", "0", "0"); # 打印生成的命令 _console.log("启动app的命令", command) # 通过adb shell执行生成的命令, 第一个参数为命令字符串, 第二个参数为配置函数, 如果不需要可以传递一个空函数, 具体用法可参考文档 r = shell.exec(command, lambda x: x) if r.isSuccess(): # 输出执行结果, 通过getOutput()方法获取输出内容 _console.log("output", r.getOutput()) else: # 输出错误信息, 如果没有错误则输出空字符串 _console.log("error", r.getStderr()) # 下面是简化版 # shell.exec(_shellCommands.launchApp("com.m8test.app.runtime", "0", "0"), lambda x: x)
# encoding: utf-8 # 创建一个adb shell对象, 需要具有adb权限 shell = $shells.newAdbShell($maps.mapOf) # 启动app的命令, 第一个参数为要启动的应用包名,例如 "com.tencent.mm"。第二个参数为启动应用所需的用户 ID。例如 "0" 代表主用户,"999" 代表应用分身或工作资料用户。第三个参数为目标显示器的 ID。例如 "0" 代表主显示器。如果此字符串为空,则命令中不会包含 --display 参数,应用将在默认显示器上启动。 command = $shellCommands.launchApp("com.m8test.app.runtime", "0", "0"); # 打印生成的命令 $console.log("启动app的命令", command) # 通过adb shell执行生成的命令, 第一个参数为命令字符串, 第二个参数为配置函数, 如果不需要可以传递一个空函数, 具体用法可参考文档 r = shell.exec(command) {} if r.isSuccess # 输出执行结果, 通过getOutput()方法获取输出内容 $console.log("output", r.getOutput) else # 输出错误信息, 如果没有错误则输出空字符串 $console.log("error", r.getStderr) end # 下面是简化版 # shell.exec($shellCommands.launchApp("com.m8test.app.runtime", "0", "0")) {}
Last modified: 08 August 2025