Using _isatty() on Windows

68 views
Skip to first unread message

Adam Armstrong

unread,
Mar 19, 2014, 5:42:29 PM3/19/14
to kl...@googlegroups.com
Hi, I am working on klisp on Windows, and I see that there is a note in ksystem.win32.c saying _isatty() might be a better choice but would need testing.

What kinds of tests are needed to see if it is suitable for implementing ksystem_isatty()?

Andres Navarro

unread,
Mar 20, 2014, 12:35:34 PM3/20/14
to kl...@googlegroups.com
The only actual use of this method is in the main interpreter in klisp.c,
which tries to find out if the input is connected to a tty.
In that case it shows the klisp version and puts up a REPL. 
If it detects it's a file, it should just process the file as if the file was
passed as an argument to the interpreter.

Ideally, this should work on all versions of windows (say, from XP to Windows 8) plus
Wine, return true for console input and return false when the input is redirected from a
file (including NULL redirections such as "klisp < NUL").

Sadly there's no current test suite for this behaviour.  If you really want to work on this,
there's a file: "test/test-interpreter.sh" that tries to test different interpreter invocation
parameters for posix systems.
You could try to port that shell script to Windows and/or add tests for this redirection thing
(which are also lacking from the posix version btw...).

Regards,
Andrés Navarro


On Wed, Mar 19, 2014 at 6:42 PM, Adam Armstrong <urulo...@gmail.com> wrote:
Hi, I am working on klisp on Windows, and I see that there is a note in ksystem.win32.c saying _isatty() might be a better choice but would need testing.

What kinds of tests are needed to see if it is suitable for implementing ksystem_isatty()?

--
You received this message because you are subscribed to the Google Groups "klisp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to klisp+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam Armstrong

unread,
Mar 20, 2014, 7:40:05 PM3/20/14
to kl...@googlegroups.com

Apparently, it just uses GetFileType() internally and checks for a return value of FILE_TYPE_CHAR.

Here are the results from trying various redirections from the command line:
- With no redirection it correctly drops to the REPL.
- When input is redirected to a file it reads the input from the file and prints to the console. It does not automatically output the result of top level expressions.
- When output is redirected to a file it does REPL but output is sent to the file.
- It drops to REPL when input is redirected to NUL, and immediately exits as it has reached the end of input.

I tried this on Windows 7 and 8.1.

Andres Navarro

unread,
Mar 21, 2014, 1:05:29 AM3/21/14
to kl...@googlegroups.com

That's what i imagined. Ideally, isatty should return false on redirect to null, but it's not a major issue. As i said before it's only used in the main interpreter.

The interpreter only checks for input redirection, so the output redirection isn't relevant here.

Oto Havle left the previous code and comment, preferring GetConsoleMode.  Any of them would probably work for this simple task, i think.

Reply all
Reply to author
Forward
0 new messages