How to Execute a Clion Program in Gnome Terminal

How do I send my CLion's output to the Gnome Terminal on Debian?

In the "Run/Debug Configurations" dialog

Sample Image

and change the executable to any custom executable, like for example the gnome terminal and then pass the your program as an argument:

Sample Image

Note that once your program exits or returns from main then the terminal will close as well.

How do i open a program in a separate terminal from c++ code?

Beside the fact that there might be more elegant solutions than invoking a terminal via C++ to execute a programm you could go with one of these:

std::string

The most obvious solution is to use std::string which provides the overloaded operator + to concat strings.

#include <string>

std::string args = "gnome-terminal ";
args += "-e 'sh ./spout";
args += "' ";

std::stringstream

std::stringstream is another option:

#include <sstream>
#include <string>

std::stringstream ss;
ss << "gnome-terminal ";
ss << "-e 'sh ./spout";
ss << "' ";
std::string args = ss.str();

strcat()

If you want to use C strings you can use something like this. Note that I do not recommend this.

#include <cstring>

strcpy(args, "gnome-terminal");
strcat(args, "-e 'sh ./spout");
strcat(args, "' ");

Please note, that the second version needs a closer look at the allocated memory for args. See strcat() for further information.

CLion - Where is my output?

CLion uses a separate directory for building and uses that as the "current directory" when running your programs.

For me working on a Linux system the directory is ~/.CLion2016.2/system/cmake/generated/project-name-<digits>.

If you want another directory, like your actual project directory, then I suggest you edit the "Run/Debug Configurations" for the program, and explicitly set the "Working directory" to the directory you want.

See Creating and Editing Run/Debug Configurations for more information.



Related Topics



Leave a reply



Submit