[clean-list] Termination of console programs under Windows

Norbert Zeh nzeh at cs.dal.ca
Tue Apr 29 14:05:41 MEST 2008


Thanks, this does exactly what I wanted, even though I don't even want to 
know what the cryptic pushes and pops in the code { ...} segment do ;)  Do 
I understand it right that the effect of this is to have a connection to 
the open console to allow output to it while the program runs, but then, 
just before exiting, trick the runtime system into thinking that it was 
running in console-less mode and thus shouldn't wait for a keypress?

-N

On Tue, 29 Apr 2008, John van Groningen wrote:

> 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