in reply to strange newline behavior in Win32 with CGI.pm and STDOUT

CGI sets binmode on STDOUT, STDIN and STDERR, among others.
  • Comment on Re: strange newline behavior in Win32 with CGI.pm and STDOUT

Replies are listed 'Best First'.
Re^2: strange newline behavior in Win32 with CGI.pm and STDOUT
by Errto (Vicar) on Dec 06, 2005 at 02:54 UTC

    Ah. That would do it. As it happens I'm using CGI::Simple but I noticed that CGI.pm has the same effect, which is why I wrote the OP that way. So now I just need to dig in and figure out what to do about it. My issue is that I'm only using the form-parsing aspects, not the HTML-generation aspects, and the data I'm writing to STDOUT has nothing to do with the CGI per se (it's actually more like log data), so I need to find a way around that behavior.

    If you're curious about what my actual program is doing it is something like this.

      Not sure if you've already worked around the problem but one apparent way is to just revert the settings with some binmode calls of your own (after CGI has been loaded):

      use CGI; binmode $_, ':crlf' for (\*STDOUT, \*STDERR, \*STDIN); print "foo\nbar\n";

      That produced the right "0D0A" line endings for me.

Re^2: strange newline behavior in Win32 with CGI.pm and STDOUT
by esskar (Deacon) on Dec 06, 2005 at 03:10 UTC
    yes. and only for $OS=~/^(WINDOWS|DOS|OS2|MSWin|CYGWIN)/;