Mailing List Archive

W95 binary output from CGI script
I'm working on a CGI script for Windows 95, and trying to send
binary data out stdout. Every time I try to send a \x0a it spits
out \x0d\x0a. This really messes up a JPEG, for example.

How can I get python to print just \x0a ?
I've tried
sys.stdout.write("\x0a")
and
rawout=os.fdopen(sys.stdout.fileno(),"wb")
rawout.write("\x0a")
and even
rawout=os.fdopen(sys.stdout.fileno(),"wb")
os.write(rawout.fileno(),"\x0a")
but I still get that damn \x0d.

How do I send only the binary data I want out to stdout ?
W95 binary output from CGI script [ In reply to ]
On Jun 22, 1999, tlhall@blackhole.nyx.net wrote:

>I'm working on a CGI script for Windows 95, and trying to send
>binary data out stdout. Every time I try to send a
it spits
>out
. This really messes up a JPEG, for example.
>
>How can I get python to print just
?
>I've tried
> sys.stdout.write("
")
>and
>....

Tom,

use a raw string -- observe the "r" before the string. See eg below:

>>> print r"abc
xyz"
abc
xyz
>>> print "abc
xyz"
abc
xyz

The first string with
was printed without being interpreted as a
line feed character. (note: eg pasted from Linux, not W95)

BTW, why do you use sys.stdout.write() instead of print?

yours-CRLF-or-LF-ly

alan kang
http://www.epls.com - free groupware online
W95 binary output from CGI script [ In reply to ]
[Tom Hall]
> I'm working on a CGI script for Windows 95, and trying to send
> binary data out stdout. Every time I try to send a \x0a it spits
> out \x0d\x0a.

Python opens the std file streams in text mode, and under all flavors of
Windows that does horrible stuff to binary data. Quoting from a different
thread,

[Charles G Waldman]
> Try running Python in unbuffered mode - with a "-u" commandline flag,
> or by setting the PYTHONUNUFFERED environment variable to a non-empty
> string.

That disables buffering, but under Windows it also causes Python to open the
std streams in binary mode.

blame-niklaus-wirth-cuz-bill-gates-is-untouchable-ly y'rs - tim