Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No console application on Linux

On Windows I normally create a Windows Desktop Application, this is because console applications display a brief black box on the screen.

I am using CodeBlocks on Linux Mint, how could I do the equivalent of the above but on Linux?

I do not want to hide the terminal window after it has been displayed.

like image 898
securityauditor Avatar asked Jul 12 '20 21:07

securityauditor


People also ask

What is the purpose of console application?

A console application facilitates the reading and writing of characters from a console - either individually or as an entire line. It is the simplest form of a C# program and is typically invoked from the Windows command prompt.

How do I make a console application with mono?

Once you’ve installed Mono, get one of your .Net programmers to create and compile a simple Microsoft Visual Studio C# console application. Just something easy, such as: If you don’t have your own tame .Net programmer, you’re going to need a Windows machine with Microsoft Visual Studio installed. (Stop making faces like that!)

Can I work from the console as a system administrator?

System administrators regularly work from the command line, but there’s more to the console than managing servers. You can do most desktop work from the console, and generally faster than you can accomplish work from a graphical user interface.

How to run a compiled application on Linux?

Transfer the compiled application from the Windows machine by using FTP or Samba, then log on to your Linux box and run the application: Surely it can’t be as simple as that?

What are the best console-based applications for X?

A Motif GUI interface is available under X. Although it does not yet support most spreadsheet file formats, it works well on its own. If you are setting up a console office suite, it’s an application that’s well worth having. The Text Presentation Tool (or Text PowerPoint) is an impressively flexible console-based application.


3 Answers

Linux does not have the same "subsystem" concept as windows: there is no difference or separation between console and desktop applications. When you start an application on Linux, it will not open a console window, unless the programmer explicitly programmed it to open one.

If the application writes anything to stdout or stderr, what happens with that depends on how exactly the application got started. By default, the application inherits the stdout and stderr of its parent process. If the application is being started from a terminal, the output will be visible on the terminal. If the application was started by the desktop environment from a menu entry, the output may go to a log file or it may be lost.

If you see a terminal window open when you run your program from the IDE, that's something that the IDE is doing for you, it's not your application. If it bothers your, I would think that the IDE has a way to disable this behavior in settings.

like image 137
Joni Avatar answered Oct 18 '22 04:10

Joni


Look into QT. It is a GUI framework that works on Linux.

You can write your code without creating a main window (or maybe you have to have a main window but it can be always hidden... it's been a while since I've used it).

Be aware though, that you may run into usability issues with this type of design... the user has no way of knowing if your app was launched or if it succeeded, when it's completed, etc.

like image 34
JoelFan Avatar answered Oct 18 '22 04:10

JoelFan


The simple way is to use (e.g.) xterm [or gnome-terminal] to get a terminal window.

Then, invoke your program from the shell [manually]:

/path_to_my_program

You may be able to configure codeblocks to do this for you.

Or, you could add some code that holds the default window open:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

int main()
{

    pid_t pid = fork();

    if (pid != 0) {
        waitpid(pid,NULL,0);
        while (1) sleep(1);
    }

    long double n;
    n=5;
    printf("n= %Lf\n",n);

    return 0;
}

UPDATE:

The invocation command can be controlled from: Settings -> Environment -> General Settings

The default is to invoke in an xterm sub-window [popup]. You may be able to change the settings to (re)use an existing [terminal] window.

Note that [a codeblocks program] cb_console_runner is used. You may be able to replace this with something more to your liking.

I do not want a GUI nor a terminal popup...

You'll need some sort of terminal to run the command in. This could be a script that diverts stdin/stdout/stderr as appropriate [and suppresses the invocation of a sub-window], so you'll have to experiment a bit.

As I mentioned above, you can just open a terminal window outside of codeblocks and then run the command manually inside it. Technically, this is not a popup. But, you lose the [automatic] debugger invocation.

like image 21
Craig Estey Avatar answered Oct 18 '22 05:10

Craig Estey