Recent

Author Topic: Writeln/write output?  (Read 718 times)

nfol

  • New Member
  • *
  • Posts: 17
Writeln/write output?
« on: January 24, 2023, 03:07:55 pm »
I try to write a simple program in Lazarus  (File > New... > Simple program).
 
I cannot figure out where the output from write/writeln goes.
In other words: what is the standard output when writing af simple program?
Do I need to include som unit?

Best regards,
Niels

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Writeln/write output?
« Reply #1 on: January 24, 2023, 03:16:31 pm »
If you are on Windows, maybe your Project Options are not set correct.
Independently of Options, this always works for me to add the Console to the Windows SubSystem of your executable:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF}
and before the last "End." put a "ReadLn;" so the console stay opened.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: Writeln/write output?
« Reply #2 on: January 24, 2023, 03:17:22 pm »
I try to write a simple program in Lazarus  (File > New... > Simple program).
 
I cannot figure out where the output from write/writeln goes.
In other words: what is the standard output when writing af simple program?
Do I need to include som unit?

Best regards,
Niels

Is this on windows? If so should be something like this:

Code: Pascal  [Select][+][-]
  1. program HelloWorld;
  2. {$mode objfpc}{$H+}
  3. {$APPTYPE CONSOLE}
  4.  
  5. begin
  6.   WriteLn('Hello Free Pascal!');
  7.   ReadLn;
  8. end.

There may be another way in Lazarus to set the app type.

If you are not running from an existing Text console one will be be be created.

https://wiki.lazarus.freepascal.org/Console_Mode_Pascal

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Writeln/write output?
« Reply #3 on: January 24, 2023, 03:17:31 pm »
Add a

Code: [Select]
readln;

to the end of your program.

WooBean

  • Full Member
  • ***
  • Posts: 229
Re: Writeln/write output?
« Reply #4 on: January 24, 2023, 03:19:22 pm »
...
I cannot figure out where the output from write/writeln goes.
In other words: what is the standard output when writing af simple program?
Do I need to include som unit?
...
Niels

You are in Linux and you want to see output during debugging, I guess.
If your Lazarus is not older than 2.0 then (what is not quite obvious)  you must use window Main menu>View>Debugger windows>Input/Output console.

Am I right?

Platforms: Win7/64, Linux Mint Ulyssa/64

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: Writeln/write output?
« Reply #5 on: January 24, 2023, 03:19:58 pm »
Heh. Four of us answering at the same time, with the roughly the same answer :D

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: Writeln/write output?
« Reply #6 on: January 24, 2023, 03:24:13 pm »
You are in Linux and you want to see output during debugging, I guess.

I don't know the default for Windows, so I was just assuming Windows.

I guess we need to hear from OP nfol what OS is being used.

nfol

  • New Member
  • *
  • Posts: 17
Re: Writeln/write output?
« Reply #7 on: January 24, 2023, 04:03:30 pm »
Thank you for your kind replies.

I'm on Windows 10.

Best regards,
Niels

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Writeln/write output?
« Reply #8 on: January 24, 2023, 04:21:59 pm »
Thank you for your kind replies.

I'm on Windows 10.

Best regards,
Niels
Use reply #1 and you are good, #2 also works since it is same, #3 can fail, #4 is not for your system  :P
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

nfol

  • New Member
  • *
  • Posts: 17
Re: Writeln/write output?
« Reply #9 on: January 24, 2023, 06:04:54 pm »
The suggestions in reply #1 and #3 work.

Thank you to you all.

Best regards,
Niels

 

TinyPortal © 2005-2018