views:

59

answers:

2

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 tc.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?

+2  A: 

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`
jonnii
Alain Ravet
jonnii
Also, it's good etiquette to mark the correct answer.
jonnii
+3  A: 

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

Steve Graham