开发者

how to capture the result of `git status` in a Rails action?

开发者 https://www.devze.com 2022-12-14 00:20 出处:网络
If you run this code in a controller action (notice the backticks) def index … `pwd >> tc.log` `git status >> tc.log`

If you run this code in a controller action (notice the backticks)

def index
  …
  `pwd >> tc.log` 
  `git status >> tc.log`
  `ls >> tc.log`
  …
end

, only the 1st and 3rd command will pipe their output to the 开发者_如何学Gotc.log file.

I'm trying to get the output of git status (f.ex) in a controller action and have tried many variations (capturing stdout, piping to a file, open3, ..) to no avail.

Any idea?


Dude check out ruby-git. Wraps up git commands in Ruby objects!


This is a total shot in the dark, but git status might not be writing to stdout.

Try doing something like:

`git status >> tc.log 2>&1`
0

精彩评论

暂无评论...
验证码 换一张
取 消