Is it possible to output LF without CR under Windows? Lua 5.3

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Is it possible to output LF without CR under Windows? Lua 5.3

Tony Papadimitriou
Hi all,
 
I’ve been trying to ‘print’ Unix style under Windows (only LF, no CR).  But, no matter what I do it does not work.
 
I’ve tried:
 
io.write(‘\n’)
io.write(‘\010’)
 
It seems that \n always gets converted to CR,LF pair just before output.
 
(Is Lua doing the translation because of Windows binary?)
 
Any ideas how to output LF’s only under Windows?
 
Thanks.
 
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to output LF without CR under Windows? Lua 5.3

Pierre Chapuis
> Any ideas how to output LFs only under Windows?

Open the file in binary mode.



Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to output LF without CR under Windows? Lua 5.3

Tony Papadimitriou
No file.  I'm interested in stdout as I want to pipe it to another command.
Can I re-open stdout in binary mode?

-----Original Message-----
From: Pierre Chapuis
Sent: Sunday, May 17, 2015 10:44 PM
To: Lua mailing list
Subject: Re: Is it possible to output LF without CR under Windows? Lua 5.3

> Any ideas how to output LFs only under Windows?

Open the file in binary mode.




Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to output LF without CR under Windows? Lua 5.3

Dirk Laurie-2
2015-05-17 21:48 GMT+02:00  <[hidden email]>:
> No file.  I'm interested in stdout as I want to pipe it to another command.
> Can I re-open stdout in binary mode?

Probably not. Manual §6.8 says:

The table io also provides three predefined file handles with their usual
meanings from C: io.stdin, io.stdout, and io.stderr. The I/O library never
closes these files.

Does io.stderr also behave like a text file under Windows?

Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to output LF without CR under Windows? Lua 5.3

Scott Morgan
In reply to this post by Tony Papadimitriou
On 17/05/15 20:48, [hidden email] wrote:

> -----Original Message----- From: Pierre Chapuis
>> Sent: Sunday, May 17, 2015 10:44 PM
>> To: Lua mailing list
>> Subject: Re: Is it possible to output LF without CR under Windows? Lua 5.3
>>
>>> Any ideas how to output LFs only under Windows?
>>
>> Open the file in binary mode.
>
> No file.  I'm interested in stdout as I want to pipe it to another
> command. Can I re-open stdout in binary mode?

Try:

f = io.open("CONOUT$", "wb")
f:write("test\ntest")
f:close()

(not perfect, and I just tested 'lua test.lua > text.txt', it didn't
work as expected, sent output to the console not the file)

Scott


Reply | Threaded
Open this post in threaded view
|

RE: Is it possible to output LF without CR under Windows? Lua 5.3

张睿
In reply to this post by Tony Papadimitriou
It's CRT (not lua) that does the translation.
In C, one can call _setmode( _fileno( stdout ), _O_BINARY ) to set output to binary mode.
I don't see how it can be done directly in lua.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of [hidden email]
Sent: Monday, May 18, 2015 3:48 AM
To: Lua mailing list
Subject: Re: Is it possible to output LF without CR under Windows? Lua 5.3

No file.  I'm interested in stdout as I want to pipe it to another command.
Can I re-open stdout in binary mode?

-----Original Message-----
From: Pierre Chapuis
Sent: Sunday, May 17, 2015 10:44 PM
To: Lua mailing list
Subject: Re: Is it possible to output LF without CR under Windows? Lua 5.3

> Any ideas how to output LFs only under Windows?

Open the file in binary mode.





Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to output LF without CR under Windows? Lua 5.3

Brigham Toskin
If you're in LuaJIT you can maybe use FFI (or similar C function/system call extension under Lua).

On Sun, May 17, 2015 at 9:20 PM, 张睿 <[hidden email]> wrote:
It's CRT (not lua) that does the translation.
In C, one can call _setmode( _fileno( stdout ), _O_BINARY ) to set output to binary mode.
I don't see how it can be done directly in lua.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of [hidden email]
Sent: Monday, May 18, 2015 3:48 AM
To: Lua mailing list
Subject: Re: Is it possible to output LF without CR under Windows? Lua 5.3

No file.  I'm interested in stdout as I want to pipe it to another command.
Can I re-open stdout in binary mode?

-----Original Message-----
From: Pierre Chapuis
Sent: Sunday, May 17, 2015 10:44 PM
To: Lua mailing list
Subject: Re: Is it possible to output LF without CR under Windows? Lua 5.3

> Any ideas how to output LFs only under Windows?

Open the file in binary mode.








--
Brigham Toskin
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to output LF without CR under Windows? Lua 5.3

Brigham Toskin
Or, since it sounds like you're trying to pipe it to a unix util on windows (mingw? cygwin?), you could insert sed or maybe something like tr into the pipeline right after Lua?

On Mon, May 18, 2015 at 3:25 PM, Brigham Toskin <[hidden email]> wrote:
If you're in LuaJIT you can maybe use FFI (or similar C function/system call extension under Lua).

On Sun, May 17, 2015 at 9:20 PM, 张睿 <[hidden email]> wrote:
It's CRT (not lua) that does the translation.
In C, one can call _setmode( _fileno( stdout ), _O_BINARY ) to set output to binary mode.
I don't see how it can be done directly in lua.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of [hidden email]
Sent: Monday, May 18, 2015 3:48 AM
To: Lua mailing list
Subject: Re: Is it possible to output LF without CR under Windows? Lua 5.3

No file.  I'm interested in stdout as I want to pipe it to another command.
Can I re-open stdout in binary mode?

-----Original Message-----
From: Pierre Chapuis
Sent: Sunday, May 17, 2015 10:44 PM
To: Lua mailing list
Subject: Re: Is it possible to output LF without CR under Windows? Lua 5.3

> Any ideas how to output LFs only under Windows?

Open the file in binary mode.








--
Brigham Toskin



--
Brigham Toskin
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to output LF without CR under Windows? Lua 5.3

Brigham Toskin
Oh, I'm stupid. If you're going the unix pipe route, just send it through dos2unix.[1] It would look like:

> lua whateverscript.lua | dos2unix ... # display, redirect, or pipe to next util here


On Mon, May 18, 2015 at 3:28 PM, Brigham Toskin <[hidden email]> wrote:
Or, since it sounds like you're trying to pipe it to a unix util on windows (mingw? cygwin?), you could insert sed or maybe something like tr into the pipeline right after Lua?

On Mon, May 18, 2015 at 3:25 PM, Brigham Toskin <[hidden email]> wrote:
If you're in LuaJIT you can maybe use FFI (or similar C function/system call extension under Lua).

On Sun, May 17, 2015 at 9:20 PM, 张睿 <[hidden email]> wrote:
It's CRT (not lua) that does the translation.
In C, one can call _setmode( _fileno( stdout ), _O_BINARY ) to set output to binary mode.
I don't see how it can be done directly in lua.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of [hidden email]
Sent: Monday, May 18, 2015 3:48 AM
To: Lua mailing list
Subject: Re: Is it possible to output LF without CR under Windows? Lua 5.3

No file.  I'm interested in stdout as I want to pipe it to another command.
Can I re-open stdout in binary mode?

-----Original Message-----
From: Pierre Chapuis
Sent: Sunday, May 17, 2015 10:44 PM
To: Lua mailing list
Subject: Re: Is it possible to output LF without CR under Windows? Lua 5.3

> Any ideas how to output LFs only under Windows?

Open the file in binary mode.








--
Brigham Toskin



--
Brigham Toskin



--
Brigham Toskin