[Python-bugs-list] [ python-Bugs-570044 ] "python -u" not binary on cygwin

noreply@sourceforge.net noreply@sourceforge.net
Fri, 09 Aug 2002 07:41:24 -0700


Bugs item #570044, was opened at 2002-06-17 15:56
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=570044&group_id=5470

Category: Python Interpreter Core
Group: None
Status: Open
Resolution: Accepted
Priority: 5
Submitted By: Sjoerd Mullender (sjoerd)
Assigned to: Martin v. Löwis (loewis)
>Summary: "python -u" not binary on cygwin

Initial Comment:
python -u is supposed to put sys.stdin and sys.stdout
in binary mode on systems where such things matter.
This does not happen on Window under Cygwin.

Try
python -u -c 'import sys;
open("x","wb").write(sys.stdin.read())' < some-text-file

and notice that the newly created file "x" has just \n
line endings instead of \r\n.

A patch is included.

----------------------------------------------------------------------

>Comment By: Sjoerd Mullender (sjoerd)
Date: 2002-08-09 16:41

Message:
Logged In: YES 
user_id=43607

mount -p says
Prefix              Type         Flags
/cygdrive           system       binmode

Now that I look more carefully at the mount output, I see
that my current directory was mounted twice, once in
textmode and once in binmode.  To make a long story short,
the python I tried this on was running on textmode mount.

I guess we can close this now?

----------------------------------------------------------------------

Comment By: Jason Tishler (jlt63)
Date: 2002-08-09 16:24

Message:
Logged In: YES 
user_id=86216

> I checked in the changes.

Thanks!

> If a execute the command "mount" it mentions
> "binmode" on every line, so I guess that means
> I'm not using text mode.

What does "mount -p" indicate?  If textmode, was
your current working directory under the cygdrive
prefix?  If so, then we completely under this
issue. If not, then I'm at a loss to explain your
reported behavior.


----------------------------------------------------------------------

Comment By: Sjoerd Mullender (sjoerd)
Date: 2002-08-09 15:38

Message:
Logged In: YES 
user_id=43607

I checked in the changes.

----------------------------------------------------------------------

Comment By: Sjoerd Mullender (sjoerd)
Date: 2002-08-09 15:26

Message:
Logged In: YES 
user_id=43607

If a execute the command "mount" it mentions "binmode" on
every line, so I guess that means I'm not using text mode.

I think the documentation should be extended to mention this
binary mode stuff, but that should be a separate bug report.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-08-09 15:18

Message:
Logged In: YES 
user_id=21627

The patch is fine, please apply it. Also add a note to
python.man documenting that this changes the streams to
binary mode.

----------------------------------------------------------------------

Comment By: Jason Tishler (jlt63)
Date: 2002-08-09 15:10

Message:
Logged In: YES 
user_id=86216

Martin,

This looks good.  Can I commit it?

Sjoerd,

> Does the patch make sense on other Cygwin
> installations than my own?

Yes, see below for the details.

My WAG is that you are using text mode mounts. Is
this correct? In my testing, I could only reproduce
this problem under text mode mounts -- never under
binary mode mounts.  Nevertheless, this patch
should be applied to guarantee proper behavior
regardless of the user's mount table.

Thanks for tracking down this issue and providing
a patch to fix it.

I wonder if there are any other binary vs. text
mode issues lurking...

BTW, the man page states the following:

-u     Force  stdin,  stdout  and  stderr  to  be
       totally unbuffered.

However, after reading the code, it is clear that
the "-u" option does more... :,)


----------------------------------------------------------------------

Comment By: Sjoerd Mullender (sjoerd)
Date: 2002-08-09 10:26

Message:
Logged In: YES 
user_id=43607

Assigned to Jason, since he seems to be the Cygwin expert. :-)
Does the patch make sense on other Cygwin installations than
my own?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=570044&group_id=5470