0

I got a problem and no nothing on the whole internet has proven a solution.

I have a C code (on codeblocks, but that's not important).

I need to open a terminal: system("gnome-terminal");

I'd like to "name" this terminal, but this is a lesser problem.

I need, from my C code, to send a command to this specified gnome-terminal console.

I need to open more consoles, each one exectuing a different file, so I'd like to name them (in my C code, for easy access).

  • Maybe this will help you: https://stackoverflow.com/questions/16073136/how-to-open-new-terminal-through-c-program-in-linux – fpiette May 11 '21 at 12:25
  • If only gnome terminal had some kind of [--execute option](http://manpages.ubuntu.com/manpages/cosmic/man1/gnome-terminal.1.html) that would let you run custom commands in it. –  May 11 '21 at 12:34

1 Answers1

0

If you have xterm available, then you can system(3) it with the following options:

xterm -name 'nameofyourterminal' -e 'command to execute' &

which can be coded in C with something similar (lacks error checking, you need to complete it) as:

char buffer[300];
snprintf(buffer, sizeof buffer, "xterm -name '%s' -e '%s' &", name, command);
system(buffer);

but gnome-terminal lacks many of the standard X11 options allowed by xterm so I cannot further help you in this sense.

Luis Colorado
  • 10,974
  • 1
  • 16
  • 31