问题描述
我们有一个android设备,作为测试的一部分,我需要在目标设备上执行一个控制台测试应用程序.如果测试应用程序检测到错误,则返回-1.
We have an android device and as part of testing I need to excute a console test application on the target device. If the test application detects an error it returns -1.
我可以使用adb shell在目标上远程运行测试应用程序,但是我找不到找到返回代码的方法.我需要这样做,以便可以将其构建到自动化测试套件中.
I can use adb shell to run the test applications remotely on the target but I can't find a way of getting back the return code. I need this so I that I can build this into an automated test suite.
我可以尝试在控制台输出中添加一些失败文本,但这有点肮脏.有谁知道更优雅的解决方案?
I could try grepping the console output for some failure text but that is a bit grubby. Does anyone know of a more elegant solution?
推荐答案
这是获取退出代码的解决方法:adb shell'{您的命令在这里}>/dev/null 2>& 1;回显$?'
This is a workaround to get the exit code:adb shell '{your command here} > /dev/null 2>&1; echo $?'
这是Ruby中adb的包装:
This is a wrapper around adb in Ruby:
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
这篇关于ADB错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!