ruby - 从 XCode plist 读取的 Ruby shell 脚本
问题描述
我正在尝试使用 /usr/bin/ruby 脚本读取 plist 值。我怎样才能做到这一点?
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
解决方案
BUGSNAG_API_KEY=$(defaults read "$FRAMEWORK/APIKeys.plist" bugsnag)
假设这是 sh,它正在运行一个命令并在字符串中捕获它的输出。在 Ruby 中,你使用反引号来做到这一点
BUGSNAG_API_KEY = `defaults read #{ENV['FRAMEWORK']}/APIKeys.plist bugsnag`
我唯一需要改变的是使用ENV
访问环境变量而不是 sh 的 $ 语法。
推荐阅读
- sql - 在 openquery 中将表作为参数传递
- scala - 无法在 spark.sql 中循环 hive sql 查询
- postgresql - 为什么 SQLAlchemy 不反映非公共模式中的表?
- ipywidgets - ipywidgets:最小化按钮宽度以仅显示图标?
- php - Symfony 字段表单在 Ajax 之后未提交
- css - 使用@font-face 的大卡特尔自定义字体不起作用
- javascript - 提交按钮不起作用,如何使它起作用?(描述中提供的代码)
- security - 在 Salesforce 中找不到重置安全令牌选项
- java - 在 java spark 中从 REST API 读取 csv
- javascript - 如何检查两个数字是否具有相同的值并将它们存储在 JavaScript 中的 Object 中?