By using this site you agree to the use of cookies and related technologies.

Learn more

Automatically Run a Console App in Terminal

How to automatically open a terminal and run a console application.

Edited: 2016-10-07 10:16

In Windows, a command prompt is automatically opened when you run a console app. Unless your application accepts user input, the prompt will open and close so fast that it can be hard to even notice. Nevertheless, it is quite obvious that the program is actually running when clicked.

In Linux, when a console application is launched by double clicking on it, nothing seem to happen at all, regardless if the program accepts input or not. The program is still executing in the background, however – it's just that it has nowhere to write its output.

It would be nice if there was a way to make the program automatically open a terminal window. And there is.

In Windows, we can simply create a batch script (.bat) file in the same directory as our program, and then run it with the pause batch command, like below:

MyConsoleApp.exe
pause

We can do something similar in Ubuntu / Linux, by creating a .desktop file which will automatically open a terminal and run our program. I.e.:

[Desktop Entry]
Name=MyProgram
Exec=/home/UserName/MyProgramName/MyProgram
Terminal=true
Type=Application

We can also open a terminal manually, navigate to the directory of our compiled program, and execute it by typing the following command:

./MyProgram