Recent

Author Topic: How to hide console correctly?  (Read 6825 times)

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
How to hide console correctly?
« on: January 26, 2016, 09:26:46 am »
Hi, all!
I've got a question about hiding console window in Windows.
I run Lazarus 1.4.4&1.6RC2 32 bit on Win7x64 and Debian Jessie 64&32 bit. I write a game Mazer in Castle Game Engine using Lazarus. And I have the following behavior: Together with main game window the console shows up in Win7 (as it seems to show up in any other Windows OS), but is hidden in Linux - I have to manually show Terminal output in Lazarus to see debug messages I send to the console.
The question is: how do I make the same thing on Windows systems? I need to see the Terminal only at development stage, but not in release without too many changes in the code.
There is a way to disable the console: by {$APPTYPE GUI} or the same option in Project>ProjectOptions>CompilerOptions>ConfigAndTarget>Win32GuiApplication checkbox. But it disables the console functionality completely - i.e. I get exception when trying to writeln debug messages to the console.
Or is the problem OS-specific and it is impossible to solve it in a simple&cross-platform way (only through something like {$IFDEF WIN32}{$IFDEF RELEASEMODE}(some OS-specific commands to 'hide' the console window){$ENDIF}{$ENDIF})?
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to hide console correctly?
« Reply #1 on: January 26, 2016, 09:43:44 am »
Well enable win32 gui in the project options
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: How to hide console correctly?
« Reply #2 on: January 26, 2016, 09:48:59 am »
Well enable win32 gui in the project options
It disables the console completely. I need it :) I just don't need it to show up if exe is launched by a user.
Maybe later I'll switch to log files... but I have much more fun stuff to do right now than to rewrite all the debugging sequence of the program.
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to hide console correctly?
« Reply #3 on: January 26, 2016, 09:50:13 am »
Well enable win32 gui in the project options
It disables the console completely. I need it :) I just don't need it to show up if exe is launched by a user.
True! so? Enable it only when compiling a release version.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: How to hide console correctly?
« Reply #4 on: January 26, 2016, 09:52:01 am »
True! so? Enable it only when compiling a release version.
Well Then I get exception on writeln(...); I need to rewrite up to 50 debug messages from different modules of the program to console... maybe I'll rewrite that part later, but not now.
UPD: I just want the console behavior in Windows the same as in Linux.
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to hide console correctly?
« Reply #5 on: January 26, 2016, 09:55:59 am »
True! so? Enable it only when compiling a release version.
Well Then I get exception on writeln(...); I need to rewrite up to 50 debug messages from different modules of the program to console... maybe I'll rewrite that part later, but not now.
A well deserved punishment. Use an ($ifdef debug}writeln(...){$ENDIF} and stop polluting your code with debug code.

I just want the console behavior in Windows the same as in Linux.
Yeah and I want a environmentally friendly, no noise, no fuel generator for each house with a life time of at least 1000 years, but in both cases that is not the way things work.
« Last Edit: January 26, 2016, 09:59:54 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10310
  • Debugger - SynEdit - and more
    • wiki
Re: How to hide console correctly?
« Reply #6 on: January 26, 2016, 03:43:03 pm »
just replace "writeln" with "debugln"

debugln checks correctly if the console is open, or not.

also it does logging if you want, and start your app with --debug-log=file

and you can use the unit LazDummyLogger (or similar, not sure) to disable it entirely
« Last Edit: January 26, 2016, 03:44:40 pm by Martin_fr »

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: How to hide console correctly?
« Reply #7 on: January 27, 2016, 10:05:24 am »
just replace "writeln" with "debugln"
Thanks, but that's also won't work, because I send ~10% of debug messages from threads (that's where I need them most) and debugln is not thread-friendly.
After 3 days of skimming through the Internet I have to confirm taazz is right. It's implssible in Windows. I'll just use log file then.
Well... practically possible (hide the window as in tray applications) - but it is not the best idea.
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: How to hide console correctly?
« Reply #8 on: January 27, 2016, 10:32:21 am »
just replace "writeln" with "debugln"
Thanks, but that's also won't work, because I send ~10% of debug messages from threads (that's where I need them most) and debugln is not thread-friendly.
After 3 days of skimming through the Internet I have to confirm taazz is right. It's implssible in Windows. I'll just use log file then.
Well... practically possible (hide the window as in tray applications) - but it is not the best idea.
OK, how about this. Instead of messing with the console window go the other way, assign a null device to stdout, stdin and stderror, this should in theory, allow writeln to work with out exceptions. Sorry for the delay but I just remembered I show a unit that did something along those lines in delphi I'll take a look in my archives when I get home.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: How to hide console correctly?
« Reply #9 on: January 27, 2016, 12:10:27 pm »
Quote
I'll take a look in my archives when I get home.
Thanks a lot. But don't bother... I've run into a huge X3D-related "bug" (feature actually) and will have to rewrite a lot of code. I'll just route everything to log file then, that'll solve the problem in a correct way. I've seen solutions by something like: http://forum.lazarus.freepascal.org/index.php/topic,30642.msg195490.html#msg195490 but that's a little bit too-low-level. I needed it simpler...
Well... that day was inevitable %) I'll still need users to be able to sumbit logs. It just came a little bit too early  ::)
I was just hoping that I'm missing something simple.
« Last Edit: January 27, 2016, 12:16:27 pm by Eugene Loza »
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

 

TinyPortal © 2005-2018