On Wed, Oct 26, 2016 at 4:48 PM, Paul Moore <p.f.mo...@gmail.com> wrote:
> Good point. We could, of course, detect when stdin is non-interactive,
> but at that point the code is starting to get unreasonably complex, as
> well as having way too many special cases. So I agree, that probably
> kills the proposal.

Isn't that check really just an isatty() check?  Or is that not
reliable enough for some reason?  Here's some code that performs that
check, and works on Linux and Windows:

#include <stdio.h>

#ifdef _WIN32
#  include <io.h>
#  define isatty _isatty
#  define fileno _fileno
#else
#  include <unistd.h>
#endif

int main( void ) {
    /* If stdin is a tty, you would launch the user's configured REPL*/
    if(isatty(fileno(stdin)))
        printf("stdin has not been redirected to a file\n");
    /* Otherwise, launch the default REPL (or maybe don't launch a REPL at all,
     * and just treat stdin as a file */
    else
        printf("stdin has been redirected to a file\n");
}
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to