Creating a new terminal and recording it in the stadium

I have an application that uses gui for most of the user interface. However, I would like to have a separate terminal window that I can write for some error checking, raw values, etc.

I know that I can create a new terminal using the command system(), but I do not know if interaction is possible.

in the best possible scenario, I would like to have a function that takes a string (a char array that I know ...) and prints it in a recently appeared console window:

sort of:

int func(char *msg) {
    static // initiate some static interface with a newly spawned terminal window.

    // check if interface is still valid

    // send data to terminal

    return 0; //succes

}
+4
source share
2 answers
  • Open the handset.
  • fork.
  • exec xterm cat /dev/fd/<rdfd>.
  • .
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>

int main(int argc, char **argv) {
    (void)argc, (void)argv;

    int fds[2];
    if(pipe(fds) == -1) {
        abort();
    }

    int child_pid = fork();
    if(child_pid == -1) {
        abort();
    }

    if(child_pid == 0) {
        close(fds[1]);
        char f[PATH_MAX + 1];
        sprintf(f, "/dev/fd/%d", fds[0]);
        execlp("xterm", "xterm", "-e", "cat", f, NULL);
        abort();
    }

    close(fds[0]);
    write(fds[1], "Hi there!\n", sizeof("Hi there!\n"));
    sleep(10);
    close(fds[1]);
    sleep(3);

    return EXIT_SUCCESS;
}

fdopen, fds[1] FILE *, fprintf .

+2

, , (, tty [n]), "" ?

, DE, , . , - , , .

0

Source: https://habr.com/ru/post/1546776/


All Articles