【发布时间】:2016-03-10 04:09:06
【问题描述】:
我有一个执行 shell 脚本的 ruby 脚本。如何将 shell 脚本数据传回 ruby 脚本。
desc "Runs all the tests"
lane :test do
sh "../somescript.sh"
print variables_inside_my_script // i want to access my script data here.
end
我可以使用从 ruby 到 shell 脚本的环境变量来执行相反的场景。
desc "Runs all the tests"
lane :test do
puts ENV["test"]
sh "../somescript.sh" // access test using $test
end
谢谢
【问题讨论】:
-
不可能。子进程继承父环境的副本;他们不能影响父母的环境。如果您想将数据从 shell 脚本传递到调用进程,最简单的方法是通过其输出。