is_tty on mingw and msys

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

is_tty on mingw and msys

David Brown-4
I'm just starting with lua - I'm hoping to use it as a simple scripting
language for testing low-level C software, as a way of speeding up the old
write-compile-test cycle.  I'm also considering using it on embedded
systems.

I'm using w2k for development, compiling with mingw in an msys environment.
Compilation (of lua 5.1) worked fine, as does running it from a standard
windows command prompt.  However, lua.exe produces no output by default when
run from within msys.  I traced this down to the lua_stdin_is_tty() macro in
luaconf.h - it would seem that _isatty() always returns 0 when running from
msys.  For my own use, I've simply hacked the luaconf.h file to return 1
here, but perhaps there is a better solution?

mvh.,

David Brown
System Developer
WestControl a.s
Norway

"Utvikling er kunsten av å vikle seg ut av det man har viklet seg inn i"


Reply | Threaded
Open this post in threaded view
|

Re: is_tty on mingw and msys

Ralph Hempel

> I'm using w2k for development, compiling with mingw in an msys
> environment.
> Compilation (of lua 5.1) worked fine, as does running it from a standard
> windows command prompt.  However, lua.exe produces no output by default
> when
> run from within msys.  I traced this down to the lua_stdin_is_tty() macro
> in
> luaconf.h - it would seem that _isatty() always returns 0 when running
> from
> msys.  For my own use, I've simply hacked the luaconf.h file to return 1
> here, but perhaps there is a better solution?

I ran into exactly this problem. On MinGW you need to start
Lua like so:

  lua -i

while on Cygwin the standard

  lua

works fine. I'm not sure of the best way to handle the situation
either...

Ralph

Reply | Threaded
Open this post in threaded view
|

Re: is_tty on mingw and msys

Mike Pall-5-2
In reply to this post by David Brown-4
Hi,

David Brown wrote:
> I'm using w2k for development, compiling with mingw in an msys environment.
> Compilation (of lua 5.1) worked fine, as does running it from a standard
> windows command prompt.  However, lua.exe produces no output by default when
> run from within msys.  I traced this down to the lua_stdin_is_tty() macro in
> luaconf.h - it would seem that _isatty() always returns 0 when running from
> msys.

Well, I got bitten by _isatty() malfunctioning previously and
tried to track this down:

Both cmd.exe and Cygwin bash attach stdin to a real terminal and
the _isatty logic works fine. Windows doesn't have pseudo-ttys,
so they need to be emulated with pipes in certain situations. In
a pure Cygwin environment, i.e. when Lua is compiled against
Cygwin libraries, this is taken care of and still works.

Alas, the MSYS shell always seems to use pipes (why?). But MinGW
binaries are (intentionally) compiled against MSVCRT. Which has
of course no knowledge about this emulation. That's why _isatty()
returns 0 when run under MSYS shell.

> For my own use, I've simply hacked the luaconf.h file to return 1
> here, but perhaps there is a better solution?

Probably not.

Maybe someone has the time to take a deeper look at MSYS and fix
this or report it as a potential bug.

Bye,
     Mike
Reply | Threaded
Open this post in threaded view
|

Re: is_tty on mingw and msys

David Brown-4
> Hi,
>
> David Brown wrote:
> > I'm using w2k for development, compiling with mingw in an msys
environment.
> > Compilation (of lua 5.1) worked fine, as does running it from a standard
> > windows command prompt.  However, lua.exe produces no output by default
when
> > run from within msys.  I traced this down to the lua_stdin_is_tty()
macro in
> > luaconf.h - it would seem that _isatty() always returns 0 when running
from

> > msys.
>
> Well, I got bitten by _isatty() malfunctioning previously and
> tried to track this down:
>
> Both cmd.exe and Cygwin bash attach stdin to a real terminal and
> the _isatty logic works fine. Windows doesn't have pseudo-ttys,
> so they need to be emulated with pipes in certain situations. In
> a pure Cygwin environment, i.e. when Lua is compiled against
> Cygwin libraries, this is taken care of and still works.
>
> Alas, the MSYS shell always seems to use pipes (why?). But MinGW
> binaries are (intentionally) compiled against MSVCRT. Which has
> of course no knowledge about this emulation. That's why _isatty()
> returns 0 when run under MSYS shell.
>
> > For my own use, I've simply hacked the luaconf.h file to return 1
> > here, but perhaps there is a better solution?
>
> Probably not.
>
> Maybe someone has the time to take a deeper look at MSYS and fix
> this or report it as a potential bug.
>
> Bye,
>      Mike
>

I guess this is something that has to be fixed (if possible) by the MSYS
developers.  MSYS has always had compromises - avoiding the overhead the
cygwin pays, at the cost of not quite following posix and not quite
emulating everything.  For my own part, hacking luaconf.h (or just using
"lua -i") is fine.

Thanks for looking into it.

mvh.,

David