Forum > Beginners

Console programs [SOLVED]

(1/1)

pascal111:
أُريد تنفيذ بعض البرامج على الـ console أي برامج بدون واجهة إستخدام رسوميّة GUI مثل البرنامج التالي كنموذج بسيط لطباعة بعض العبارات ولقد إخترت خيار Program من القائمة المعروضة لإنشاء مشروع جديد Create a new project وقُمتُ بتنفيذ البرنامج ولكن لم أرى نتيجة التنفيذ على الـ console ولا شاشة أو نافذة الـ console نفسها.

google translate:

"I want to implement some programs on the console, i.e. programs without a GUI, such as the following program as a simple form to print some statements and I chose the Program option from the displayed menu to create a new project and I executed the program but I did not see the result of the implementation on the console nor a screen or The console window itself."



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes  { you can add units after this }; begin   write('Do you think if you encouraged me to seek money');  write('that I''ll have some?!!');  writeln('It doesn''t work as you think.');end.  

wp:
I think you are on Windows. When you run your program out of Lazarus the console is opened, the program is executed and the console closes automatically. This is so fast that one might think that nothing did happen. Of course, when you run your program from a console window directly then you do see the output.

What I always do is to add a Readln at the end of the console program, at least for testing purposes. Then the user must press ENTER to close the console:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes  { you can add units after this }; begin   write('Do you think if you encouraged me to seek money');  write('that I''ll have some?!!');  writeln('It doesn''t work as you think.');   WriteLn;  WriteLn('Press ENTER to close the progam.');  ReadLn;end.

pascal111:

--- Quote from: wp on May 11, 2021, 04:24:06 pm ---I think you are on Windows. When you run your program out of Lazarus the console is opened, the program is executed and the console closes automatically. This is so fast that one might think that nothing did happen. Of course, when you run your program from a console window directly then you do see the output.

What I always do is to add a Readln at the end of the console program, at least for testing purposes. Then the user must press ENTER to close the console:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes  { you can add units after this }; begin   write('Do you think if you encouraged me to seek money');  write('that I''ll have some?!!');  writeln('It doesn''t work as you think.');   WriteLn;  WriteLn('Press ENTER to close the progam.');  ReadLn;end.
--- End quote ---

قُمتُ بإضافة ما قد نصحت به ولكن لا يزال الوضع كما هو عليه ،لا تغيير ولكنّ بيئة Lazarus هذه المرّة إنتظرت منّي ضغط زر توقف في الـ debug.

google translate:

"I added what I you advised but the situation is still the same, no change, but the Lazarus environment this time waited for me to press the pause "stop" button in "of" the debug."

Martin_fr:
The Readln is for Windows only.

On Linux: menu > View > Debug Windows > Console output

On Mac:
menu > Tools > options > Debugger => in the property grid: "LaunchNewTerminal" = True
(But that will affect all apps. So you get a terminal for GUI apps too. And you must close the terminal yourself when the app exited)

pascal111:

--- Quote from: Martin_fr on May 11, 2021, 04:43:27 pm ---The Readln is for Windows only.

On Linux: menu > View > Debug Windows > Console output

On Mac:
menu > Tools > options > Debugger => in the property grid: "LaunchNewTerminal" = True
(But that will affect all apps. So you get a terminal for GUI apps too. And you must close the terminal yourself when the app exited)

--- End quote ---

كلامكـ صائب كما في الصورة التاليّة. تفاصيل دقيقة مُفيدة ،أشكُركـ!

google translate:

"Your words are correct, as in the following picture "image". Helpful minute "accurate" details, thank you!"

(https://i.postimg.cc/py5X7VyC/Screenshot-at-2021-05-11-17-02-47.png)

Navigation

[0] Message Index

Go to full version