【问题标题】:Shell Script Sequencing with Rake使用 Rake 进行 Shell 脚本排序
【发布时间】:2011-02-03 12:30:48
【问题描述】:

我正在开发一个 rake 实用程序,并希望实现下面提到的一些东西:

在我的 Rake 文件中有一些 shell 命令按顺序排列。我想要的是序列应该等待上一个命令完成处理,然后再移动到下一个。

sh "git commit -m \"#{args.commit_message}\"" do |ok, res|
  # Do some processing
end

sh "git push heroku master"

所以,在上面的例子中,我想要的是

sh "git push heroku master"

中的处理之前不应该执行
sh "git commit -m \"#{args.commit_message}\"" do |ok, res|
  # Do some processing
end

已完成。

如果我可以将 shell 命令的输出存储在 Ruby 变量中,以便在需要时用于进一步操作。

期待社区成员的回复。

提前致谢。

【问题讨论】:

    标签: ruby git shell rake


    【解决方案1】:

    除非我遗漏了什么,否则您可以使用 Ruby 的内置命令之一来执行系统命令;请查看http://blog.jayfields.com/2006/06/ruby-kernel-system-exec-and-x.html 了解更多信息。

    该链接中没有提到它,但我可能会选择使用反引号(我不确定它是否与系统方法有任何不同)来执行 shell 命令,例如:

    output = `ls`     # => gets the output of the ls command to the output variable
    

    ...因此,我不明白你为什么不能这样做:

    output = `git commit -m "#{args.commit_message}"` do |ok, res|
      # Do some processing
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-17
      • 2020-12-27
      • 1970-01-01
      • 2012-03-19
      相关资源
      最近更新 更多