我需要执行以下 shell 命令并读出 rake 变量中的输出:
`#{security_bin} find-identity -v -p codesigning #{keychain_path} | grep "$1" | awk -F\" '/"/ {print $2}' | head -n1`
如您所见,我使用反引号告诉 rake 解释器“这是要执行的 shell 命令”。问题是它不起作用,因为在调用中使用单引号会破坏解析或其他东西,并且 ruby 不知道条目在哪里结束。
我得到的错误如下:
rake xamarin:create_keychain
Deleted the old one...
About to retrieve identity...
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
流程发生的函数如下(尽管我仍然怀疑上面提到的行:
def create_temp_keychain(keychain_path, p12path)
security_bin='/usr/bin/security'
delete_keychain(keychain_path)
`/usr/bin/security create-keychain -p tempass #{keychain_path}`
`#{security_bin} set-keychain-settings -lut 7200 #{keychain_path}`
`#{security_bin} unlock-keychain -p "tempass" #{keychain_path}`
`#{security_bin} import #{p12path} -P "" -A -t cert -f pkcs12 -k #{keychain_path}`
`#{security_bin} list-keychain -d user -s #{keychain_path} "login.keychain"`
puts "About to retrieve identity..."
identity_output = `#{security_bin} find-identity -v -p codesigning #{keychain_path} | grep "$1" | awk -F\" '/"/ {print $2}' | head -n1`
puts identity_output
end
在 ruby 中执行以下命令的正确方法是什么?