简体   繁体   English

红宝石变量bash shell命令输出分配的capistrano

[英]ruby variable bash shell commands output assigned capistrano

I am writing a task in capistrano 3.4 to print git version number in deployed code. 我在capistrano 3.4中编写了一个任务,以在部署的代码中打印git版本号。 I am able to print the code. 我能够打印代码。 Here i want to store the output code in some variable. 在这里我想将输出代码存储在某个变量中。 How i can store the output of shell command in ruby variable. 我如何将shell命令的输出存储在ruby变量中。 below is my task. 下面是我的任务。

desc "version number"
task :set_current_version do
  on roles(:app) do
    execute "version=#{current_path}/REVISION ; cat $version "
  end
end

I need to store the cat $version output in variable. 我需要将cat $ version输出存储在变量中。 So i can refer this variable in another code. 所以我可以在另一个代码中引用此变量。

I got this solved this myself by using capture method below is example. 我通过以下捕获方法自己解决了这个问题。

 on '1.example.com' do
   if test("[ -f somefile.txt ]")
     execute(:cp, 'somefile.txt', 'somewhere_else.txt')
   end
   ls_output = capture(:ls, '-l')
 end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM