[clean-list] Termination of console programs under Windows
John van Groningen
johnvg at cs.ru.nl
Tue Apr 29 13:06:57 MEST 2008
Norbert Zeh wrote:
>I have a problem I found at least two posts about in the mailing list archive, but the questions were never answered satisfactorily. So let me try to be very clear about the issue:
>
>I'm writing a program that outputs stuff to the console but does not require console input, ie, a regular command line tool. The expected behavior of such a program is that it does whatever it has to do and whenever it is done, it returns to the shell prompt.
>
>Using the four different settings for console interaction in the project options, I can get the following behaviors:
>
>1. Display of the regular program output + display of final result of
> computation + wait for input of return key to return to shell prompt.
>
>2. (No return value) Same as 1 without display of final result.
>
>3. (No console) All output is placed into a separate console window which
> closes immediately when the program exits, but nothing appears in the
> console where I actually started the program from the shell.
>
>So none of these options give me the behavior I would expect from a command line tool. The question is: How can I write a program in CLEAN that outputs stuff to the console and then returns me to the shell prompt without waiting for me to press Enter?
Unfortunately it does not seem possible with the windows API to determine
if a command line window has already been opened. You therefore can pass "-con"
as an argument when the application is started from a command line window.
In that case no new command line window will be opened and the program
will not wait for a key to be pressed when the program has finished.
You can also set the global variable console_flag to non zero at runtime
to prevent waiting for a key press.
For example using the following function:
set_console_flag :: Int;
set_console_flag = code {
pushL _console_flag
push_b_a 0
pop_b 1
push_node EMPTY 0
push_a_b 0
pop_a 1
}
Start
| set_console_flag<>0
= 0
Kind regards,
John van Groningen
More information about the clean-list
mailing list