Forum > Linux

[SOLVED] Problem running external program under Linux

(1/7) > >>

Dear ALL,

I am struck with a strange problem when attempting to run an external program from a Lazarus GUI application under Linux.

I cannot distribute my real application at this time, but it is a relatively straightforward program which executes a C program, passing the name of text file as its only argument and counts the lines in the file; the program then enters a command loop where the user must type 'quit' in order to exit the program. Under Windows, the application works fine, but it fails under Linux. without issuing any error messages.

I am running Lazarus 1.8.2 under Lubuntu 18.04.5 LTS. I have installed Lazarus from the Ubuntu repositories, and therefore that is not the most recent version.

The only reasonable explanation I can find for this problem is that it may be related to that old version of Lazarus. However, before updating, I would like to be sure that it is really the problem. Could someone give it a try under a more recent version of Lazarus for Linux?

My sample code is attached. I hope that perusal of the code will make the problem easier to understand.

Thanks in advance!

With best wishes,


I don't have a windows machine to compare to right now but I believe the issue you are experiencing is due to how Linux handles console applications differently than Windows. I assume you expect a command prompt to be opened on Linux when the counter program is run?

On Linux you must execute a terminal emulator explicitly (such as xterm) and then pass it arguments to execute your counter program rather than launching the counter program directly.

Jurassic Pork:
have you tried to launch your compiled program in a xterm ? if you launch your program in the IDE , display the console In/out window ->  View/Debug Windows/Console In/Output  may be View/Debug Windows/Console Terminal in your Lazarus version.
Friendly, J.P

The C program seems to always return exit code 0; in *nix you should instead (or also) check ExitStatus, which will tell you if there was some problem running the program irrespective of what the program itself returns as ExitCode.

Dear ALL,

Thank you very much indeed for your replies. However, I am still at a loss. I could not fully understand the issue with 'xterm'. But as far as I can see, a console program cannot be executed from a GUI application under Linux in the same way it can be under Windows.

How do I 'execute a terminal emulator explicitly', as suggested by @rsz? Could an example be provided? Also, I would appreciate a tip on how to check ExitStatus as suggested by @lucamar. Unfortunately, none of the explanations provided in the links below mention GUI applications:

I attach a slightly updated version of my sample code, now including a 'runcounter.pas' program as a console-mode application, which works fine under both Linux and Windows.

Thanks again for your time and patience!

With best wishes,


[0] Message Index

[#] Next page

Go to full version