It's important to understand that MSYS2 supports running two different
types of programs.

1) Native Windows programs that are compiled with a MinGW compiler,
use msvcrt.dll as their libc, and do not have access to all features
of POSIX.

2) Programs the use the msys-2.0.dll POSIX emulation layer.

Most people want to be compiling native Windows programs because they
want to distribute their programs to end users outside of MSYS2.  It
looks like you've already figured out what toolchain to install to
compile a native Windows program and I would not recommend switching
with the information you have provided.

MinTTY does not actually make a Windows Console, so native Windows
windows programs don't recognize that they are talking to a TTY when
they use MinGW's isatty function (which basically just calls
Microsoft's version of that function).  This is why programs like
"irb" can be pretty hard to use in MSYS2.

Mihael Konev has been submitting patches to the mingw-w64 in an
attempt to get isatty to work the way that you would expect, and
return true in MinTTY.  Here is the latest version of his patch on the
mingw-w64 mailing list:

https://sourceforge.net/p/mingw-w64/mailman/message/35589741/

It's not clear if the mingw-w64 project will accept this patch.  If
you want a version of isatty that works properly for you today, you
might consider just using the code from that patch in your program,
without modifying mingw-w64.

--David Grayson

On Thu, Mar 16, 2017 at 3:00 PM, Computer Jock <computerj...@mail.com> wrote:
> I'm trying to duplicate the code in bash/test that checks that stdout is
> a "terminal". Compiling and running the following:
>
> #include <stdio.h>
> #include <io.h>
> int main( int ac, char **av ) {
>    printf( "isatty(stdout): %s\n", isatty( fileno(stdout) )? "yes" : "no" );
> }
>
> returns "no" when run in mintty but "yes" for cmd|tcc.
>
> If I run bash or test from cmd|tcc, -t returns true >and< it returns
> true when run from mintty.
>
> I've downloaded the source for coreutils and bash but I can find nothing
> that appears in any way special.
>
> I noticed that ldd /usr/bin/test loads msys-2.0.dll while my program
> above loads msvcrt.dll
>
> Could that be the difference? If so, how would I compile&link my sample
> program against msys-2.0.dll?
>
> Or my real question: how can I tell if stdout is redirected or the
> "terminal" from within a program?
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Msys2-users mailing list
> Msys2-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/msys2-users

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Msys2-users mailing list
Msys2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/msys2-users

Reply via email to