Recent

Author Topic: GUI (not Console App) print to console  (Read 17425 times)

PaulANormanNZ

  • Full Member
  • ***
  • Posts: 117
GUI (not Console App) print to console
« on: September 14, 2011, 09:20:52 am »
Hi,

Is it possible for a Lazarus GUI application (not a console app) called from the shell or command line to write a string back to the command line or shell that called it while running or at end of execution?

I've had a hunt a round but can not find an answer to this yet.

Or can a console app show a form?

Paul

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: GUI (not Console App) print to console
« Reply #1 on: September 14, 2011, 09:28:36 am »
If you open "project --> Project Options --> Linking" and disable the "Win32 Gui Application" checkmark you can write to the command line with "WriteLn".
1.0/2.6.0  XP SP3 & OS X 10.6.8

PaulANormanNZ

  • Full Member
  • ***
  • Posts: 117
Re: GUI (not Console App) print to console
« Reply #2 on: September 14, 2011, 10:15:53 am »
If you open "project --> Project Options --> Linking" and disable the "Win32 Gui Application" checkmark you can write to the command line with "WriteLn".

Are there any other implications of doing that please?

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: GUI (not Console App) print to console
« Reply #3 on: September 14, 2011, 10:55:22 am »
The only one I can think of is that - when you don't run the program from the command line - you will still get a DOS window when you start it.  It opens and just sits there at the background then.   
I'm talking about Windows here but I assume that holds true for Linux too. 
Other than that it just works normally.
1.0/2.6.0  XP SP3 & OS X 10.6.8

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: GUI (not Console App) print to console
« Reply #4 on: September 14, 2011, 11:02:23 am »
If you open "project --> Project Options --> Linking" and disable the "Win32 Gui Application" checkmark you can write to the command line with "WriteLn".

Are there any other implications of doing that please?

If you forget to disable the -WG option, then a writeln() statement will raise an Exception or a runtime error, because then stdout is not open.
(stdout is the handle where writeln() normally sends its output to)

Another option is to use DebugLn() from LCLProc unit.

Bart

PaulANormanNZ

  • Full Member
  • ***
  • Posts: 117
Re: GUI (not Console App) print to console
« Reply #5 on: September 14, 2011, 11:52:29 am »
Thank you it is really great, works easier than I recall the same kind of thing in Delphi.

Paul

Rails

  • Guest
Re: GUI (not Console App) print to console
« Reply #6 on: September 14, 2011, 12:40:33 pm »

If you forget to disable the -WG option, then a writeln() statement will raise an Exception or a runtime error, because then stdout is not open.
(stdout is the handle where writeln() normally sends its output to)

Another option is to use DebugLn() from LCLProc unit.

Bart
Interesting.

I am very new to Lazarus, but I have been writing to stdout with writeln() since I started my project. I find it does not matter whether -WG is checked or not. I do not get any exceptions either way. This is true whether the program is run in the IDE or started from the command line. I'm using Debian Linux.

Why would stdout be closed?





Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: GUI (not Console App) print to console
« Reply #7 on: September 14, 2011, 12:50:25 pm »
@ Rails

AFAIK this is valid only in Windows. -WG options does not affect Linux.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Rails

  • Guest
Re: GUI (not Console App) print to console
« Reply #8 on: September 14, 2011, 02:39:38 pm »
@ Rails

AFAIK this is valid only in Windows. -WG options does not affect Linux.

OK, I wondered about that. The -WG option seems to be checked by default. I wasn't sure if that option had any implication for someone working on a cross platform application, other than during compilation for the Windows target.

The OP did not specify an OS.  I guess most people here are using Windows.


TurboRascal

  • Hero Member
  • *****
  • Posts: 672
  • "Good sysadmin. Bad programmer."™
Re: GUI (not Console App) print to console
« Reply #9 on: September 14, 2011, 06:32:52 pm »
It opens and just sits there at the background then.   
I'm talking about Windows here but I assume that holds true for Linux too. 

It's different in Linux (and Unixes in general). The stdout is NOT closed for GUI programs, and if you start the program from the command line it is written to the terminal it was started from. Even when started from GUI (say, a Run dialog), the stdout can still be written to, but is discarded since there it is not redirected anywhere; you can however redirect the output to a file, e.g. type something like this in a Run dialog: myprog > myprog.log
Regards, ArNy the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

z505

  • New Member
  • *
  • Posts: 38
  • think first, code after
Re: GUI (not Console App) print to console
« Reply #10 on: May 01, 2017, 03:29:57 pm »
If you open "project --> Project Options --> Linking" and disable the "Win32 Gui Application" checkmark you can write to the command line with "WriteLn".

Sorry, thread necromancer here...
This has changed to a different location in the lazarus options now:

Project Options --> Config and Target

Just FYI to the people reading these old threads.

p.s. Thread Necromancer:
http://i1362.photobucket.com/albums/r698/noahski/Mobile%20Uploads/thread-necromancy_zpslduenrqk.png
think first, code after

 

TinyPortal © 2005-2018