Finding out if an engine is opened in a console.

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Finding out if an engine is opened in a console.

Postby Pradu » 03 Jul 2005, 00:27

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?
User avatar
Pradu
 
Posts: 343
Joined: 12 Jan 2005, 19:17
Location: Chandler, Arizona, USA

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

Postby Alessandro Scotti » 03 Jul 2005, 00:48

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.
User avatar
Alessandro Scotti
 
Posts: 306
Joined: 20 Nov 2004, 00:10
Location: Rome, Italy

Thanks a bunch

Postby Pradu » 03 Jul 2005, 01:27

Thanks a lot Alessandro. isatty works for Unix systems.
User avatar
Pradu
 
Posts: 343
Joined: 12 Jan 2005, 19:17
Location: Chandler, Arizona, USA


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 5 guests