1

Resolved

sys.stdout.isatty() always returns True

description

To reproduce:
 
C:>ipy -c "import sys; print sys.stdout.isatty()"
True
C:>ipy -c "import sys; print sys.stdout.isatty()" > out
C:>type out
True

comments

jdhardy wrote Sep 18, 2012 at 6:43 PM

I don't think, in general, that IronPython can tell them apart, but False is probably safer.

pekkaklarck wrote Sep 18, 2012 at 7:58 PM

It seems you cannot do this directly using .NET 4.0 APIs, but the information is available via win32 APIs:
http://stackoverflow.com/questions/3453220/how-to-detect-if-console-in-stdin-has-been-redirected

.NET 4.5 makes this easier:
http://msdn.microsoft.com/en-us/library/system.console.isoutputredirected%28v=VS.110%29.aspx

If this problem cannot be easily fixed under these circumstances, I actually prefer True over False as the return value. Well behaving tools that enable fancy console output when sys.stdout.isatty() is True work better currently. Really well behaving tools allow unconditionally turning fancy outputs off and that functionality can be used when redirecting.

jdhardy wrote May 11 at 6:24 AM

Fixed in c02becc.