ADB错误代码

时间:2012-02-21 14:37:18

标签: android

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

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

我可以尝试使用控制台输出来获取某些失败文本,但这有点肮脏。有谁知道更优雅的解决方案?

2 个答案:

答案 0 :(得分:9)

这是获取退出代码的解决方法: adb shell'{your command here}> / dev / null 2>& 1; echo $?'

这是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

答案 1 :(得分:4)

你可以使用Facebook的fb-adb,一个"一个更好的Android设备外壳" "传播程序退出状态,而不是总是退出状态0"。