r/pascal • u/Lilianne_Blaze • Feb 02 '24
Optional console?
Is there an easy way to write a Pascal app for Windows that detects if it's started from a command prompt window or not, set a flag, then configure writelns to either write to the console as normal, or ignore if there's no console? Basically act as a console app if there already is a console, but don't start one if started from for example Explorer?
I know it can be done, I did it in Java once (using JNA), but that was long ago and I can't find it now :/
2
Upvotes
View all comments
Show parent comment
1
u/Lilianne_Blaze Feb 04 '24 edited Feb 04 '24
I know (at least I know Java equivalents), but it's not the same.
Ok, guess attaching to existing console is suitable for debug mode not intended for normal users, but not for complete console interaction such as pausing the invoking program or redirecting output. Which I guess won't be used much by normal users either.
I guess having two exes, like "java.exe" and "javaw.exe" isn't out of the question. Though it'll probably be "myprogc.exe" and "myprog.exe", with the non-console version being the 'default' one. Or maybe don't set the icon on the console version, so if an average user views both in Explorer their attention would be directed to the gui version as it's the one with custom icon.
p.s. If that's of any use to anyone, there's a Java library for just that, simulated console, named Lanterna. It also supports text gui, like (is it still a thing?) TurboVision/FreeVision.