TTY::Command::Result labeling command outputs incorrectly?
ryderstorm opened this issue · 6 comments
I'm running a command like this:
git clone git@github.com:some_organization/some_repo.git /tmp/d20161007-16174-ldlovj/frontend
with this code:
cmd = TTY::Command.new(printer: :quiet)
command = "git clone #{repositories[repository.to_sym]} #{clone_dir}"
result = cmd.run(command)
The command succeeds and I see the output from the command, but either the output is being mapped incorrectly or I'm misunderstanding something, because result
looks like this:
pry(main)> result.as_json
{
"status" => 0,
"out" => "",
"err" => "Cloning into '/tmp/d20161007-16174-ldlovj/frontend'...\n"
}
Shouldn't it look like this:
{
"status" => 0,
"out" => "Cloning into '/tmp/d20161007-16174-ldlovj/frontend'...\n",
"err" => ""
}
❓ 😕
Hey Damien, thanks for using the library.
In mac & linux world based on my experience, just because something runs with status code of zero, it doesn't necessairly direct all output to stdout, some stuff is quite often written to stderr. However, I'm not denying the fact that there maybe a bug in actually assigning correct output. Do you have time to investigate?
Sure, @piotrmurach - just tell me what you need.
Ideally if you could add a test that replicates this problem and/or some simple example to get it replicated that would definietly speed up process of fixing. However, if you feel you have time I'm also happy to accept PR fixing the issue.
Will do. I should have some time to look at it this upcoming Sunday.
Hey, I just had some time to look into this and I believe the output to be correct. According to git clone docs
Progress status is reported on the standard error stream by default when it is attached to a terminal...
If you run git status
that outputs to stdout you get what you expect:
cmd = TTY::Command.new(printer: :quiet)
command = "git status"
result = cmd.run('git status')
result.out # => "On branch master\nUntraced files..."
result.err # => ""
Nice find, thanks for looking into it! 👍