gpt4 book ai didi

android - 亚行错误代码

转载 作者:IT老高 更新时间:2023-10-28 23:00:47 25 4
gpt4 key购买 nike

我们有一个 android 设备,作为测试的一部分,我需要在目标设备上执行一个控制台测试应用程序。如果测试应用程序检测到错误,它会返回 -1。

我可以使用 adb shell 在目标上远程运行测试应用程序,但我找不到取回返回码的方法。我需要这个,以便我可以将它构建到一个自动化测试套件中。

我可以尝试在控制台输出中查找一些失败文本,但这有点肮脏。有谁知道更优雅的解决方案?

最佳答案

这是获取退出代码的解决方法:adb shell '{您的命令} >/dev/null 2>&1;回声 $?'

这是 Ruby 中 adb 的包装器:

def adb(opt)
input = "#{adb_command} #{opt[:command]} #{opt[:params]}"
puts "Executing #{input}...\n"
output = nil
exit_code = 0

def wait_for(secs)
if secs
begin
Timeout::timeout(secs) { yield }
rescue
print 'execution expired'
end
else
yield
end
end

wait_for(opt[:timeout]) do
case opt[:command]
when :install, :push, :uninstall
output, exit_code = `#{input}`, $?.to_i
when :shell
input = "#{adb_command} shell \"#{opt[:params]}; echo \\$?\""
output = `#{input}`.split("\n")
exit_code = output.pop.to_i
output = output.join("\n")
else
raise 'Error: param command to adb not defined!'
end
end

return if opt[:ignore_fail] and output =~ /#{opt[:ignore_fail]}/
raise output unless exit_code == 0
end

关于android - 亚行错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9379400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com