开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜