piotrmurach / tty-command

Execute shell commands with pretty output logging and capture stdout, stderr and exit status.
https://ttytoolkit.org
MIT License
400 stars 34 forks source link

TTY::Command::Result labeling command outputs incorrectly? #23

Closed ryderstorm closed 7 years ago

ryderstorm commented 7 years ago

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" => ""
}

:question: :confused:

piotrmurach commented 7 years ago

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?

ryderstorm commented 7 years ago

Sure, @piotrmurach - just tell me what you need.

piotrmurach commented 7 years ago

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.

ryderstorm commented 7 years ago

Will do. I should have some time to look at it this upcoming Sunday.

piotrmurach commented 7 years ago

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 # => ""
ryderstorm commented 7 years ago

Nice find, thanks for looking into it! :+1: