ConEmu icon indicating copy to clipboard operation
ConEmu copied to clipboard

Problem with python subprocess and stderr redirection when run in conemu

Open jankatins opened this issue 9 years ago • 4 comments

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?

jankatins avatar Feb 15 '16 12:02 jankatins

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

Maximus5 avatar Feb 15 '16 12:02 Maximus5

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.

scopatz avatar Feb 19 '16 05:02 scopatz

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'

Maximus5 avatar Nov 03 '17 16:11 Maximus5

I have some troubles with Cmder but not ConEmu:

  • Python 3.11.1 and 3.10 interactive modes do not work for me on Cmder. The interactive prompt does not show (it just prints whatever I type, and I have to close the window).

  • In Golang, the stdout is not a CharDevice as a normal terminal should be, so it looks like the output is piped, this function returns false:

// 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.

ilius avatar Feb 05 '23 04:02 ilius