首页 > 解决方案 > 从 XCode plist 读取的 Ruby shell 脚本

问题描述

我正在尝试使用 /usr/bin/ruby 脚本读取 plist 值。我怎样才能做到这一点?

Bugsnag API 脚本

fork do
  Process.setsid
  STDIN.reopen("/dev/null")
  STDOUT.reopen("/dev/null", "a")
  STDERR.reopen("/dev/null", "a")

  require 'shellwords'

  BUGSNAG_API_KEY=$(defaults read "$FRAMEWORK/APIKeys.plist" bugsnag) // Convert this to ruby

  Dir["#{ENV["DWARF_DSYM_FOLDER_PATH"]}/*/Contents/Resources/DWARF/*"].each do |dsym|
    system("curl --http1.1 -F apiKey={BUGSNAG_API_KEY} -F dsym=@#{Shellwords.escape(dsym)} -F projectRoot=#{Shellwords.escape(ENV["PROJECT_DIR"])} https://upload.bugsnag.com/")
  end
end

标签: rubyxcodebugsnag

解决方案


BUGSNAG_API_KEY=$(defaults read "$FRAMEWORK/APIKeys.plist" bugsnag)

假设这是 sh,它正在运行一个命令并在字符串中捕获它的输出。在 Ruby 中,你使用反引号来做到这一点

BUGSNAG_API_KEY = `defaults read #{ENV['FRAMEWORK']}/APIKeys.plist bugsnag`

我唯一需要改变的是使用ENV访问环境变量而不是 sh 的 $ 语法。


推荐阅读