Page 1 of 1

Finding out if an engine is opened in a console.

PostPosted: 03 Jul 2005, 00:27
by Pradu
Is there a way (in both Unix and Win32) to find out whether stdin is through a console or if it is redirected to a pipe?

Re: Finding out if an engine is opened in a console.

PostPosted: 03 Jul 2005, 00:48
by Alessandro Scotti
I don't remember how standard it is, but the function should be called isatty() or istty(), possibly with a leading underscore. Under Win32, there is also GetConsoleMode:
Code: Select all
    HANDLE hInput = GetStdHandle( STD_INPUT_HANDLE );

    DWORD dwConsoleMode;

    bool isInputPipe = false;

    if( ! GetConsoleMode( hInput, &dwConsoleMode ) ) {
        isInputPipe = PeekNamedPipe( hInput, 0, 0, 0, &dwAvailable, 0 ) != 0;
    }

Sorry I don't have a corresponding snippet for Unix, but there I don't need this information.

Thanks a bunch

PostPosted: 03 Jul 2005, 01:27
by Pradu
Thanks a lot Alessandro. isatty works for Unix systems.