Page 1 of 1
input()?
Posted: Fri Oct 03, 2025 8:50 pm
by ppnl
I was using the input() function to halt program execution so I could read output before the console closed. Like this:
Code: Select all
OpenConsole()
Input()
End
CloseConsole()
Just hit enter to end the program. Works fine in the IDE. But compile and run the .EXE and instead of closing the program it starts a whole new instance of the program so that I have two consoles open.
Is this intended?
Re: input()?
Posted: Sat Oct 04, 2025 9:06 am
by infratec
First:
What doy you think End means?
A command after End is non sense.
Second:
Have you choosen Console app in Compiler settings?
Third:
From which OS are you talking?
Re: input()?
Posted: Sat Oct 04, 2025 10:52 am
by Axolotl
well, it is always a good idea to look at the docs/help.
Easy by pressing F1 on a keyword.
Anyway, I have done the following for your convenience:
Code: Select all
; Important Remark (borrowed from Help):
;
; On Microsoft Windows, there are two different executable formats: Win32 and Console.
; If you want to create a standard console application, like 'dir', 'del' etc. you must compile
; the executable using the 'Console' format (Compiler Option menu in the PureBasic IDE).
;
; On Linux and OS X, there is no special Console format however setting the Compiler option
; to 'Console' will launch a terminal window automatically when you run your program from the IDE.
;
Define name$
If OpenConsole() ; if result is 0, it has failed and all further call to console functions must be disabled.
Print("Please enter your name: ") ; Ask for name
name$ = Input() ; Wait for user input
PrintN("Hello " + name$)
PrintN("")
; PrintN("Press return to exit")
PrintN("Press return to close console")
Input() ; Wait for Enter/Return Key pressed by user w/o any other keys before
CloseConsole()
EndIf
; acc. to help:
;
; End .. Ends the program execution correctly.
; The 'ExitCode' optional parameter can be specified if the program need to returns an error code.
;
End ;ExitCode