Maximus5 / ConEmu

Customizable Windows terminal with tabs, splits, quake-style, hotkeys and more
https://conemu.github.io/
BSD 3-Clause "New" or "Revised" License
8.57k stars 573 forks source link

Problem with python subprocess and stderr redirection when run in conemu #546

Open jankatins opened 8 years ago

jankatins commented 8 years ago

If you run python in a conemu (in this case cmder) session, it seems that you can't used things like ´stderr=subprocess.PIPE`:

mel@ANYBODY-MEL ~/Documents/xonsh $ subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
b'master\n'
mel@ANYBODY-MEL ~/Documents/xonsh $ subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'],stderr=subprocess.PIPE)
b''

https://github.com/scopatz/xonsh/issues/666

Any idea what this could be?

Maximus5 commented 8 years ago

What version of python? What shall I do to reproduce?

scopatz commented 8 years ago

It happens on Python 3.4 and Python 3.5. You can see a longer and more detailed discussion in scopatz/xonsh#666. But all you need to do to reproduce, as a single command is run:

$ python -c "import subprocess; print(repr(subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'],stderr=subprocess.PIPE)))"

to see that it is an empty line, and

$ python -c "import subprocess; print(repr(subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])))"

to see that it is not.

Maximus5 commented 6 years ago

I do not see problems with subprocess.PIPE in current ConEmu build.

> python -c "import subprocess; print(repr(subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'],stderr=subprocess.PIPE)))"
b'master\n'
ilius commented 1 year ago

I have some troubles with Cmder but not ConEmu:

// check if standard output is connected to a terminal
func OutputIsTerminal(stdout *os.File) bool {
    o, _ := stdout.Stat()
    if (o.Mode() & os.ModeCharDevice) == os.ModeCharDevice {
        return true
    }
    // Pipe
    return false
}

These are obviously Cmder issues, but just wanted to let you know. Make sure to test on ConEmu itself before making conclusions.