-
-
Notifications
You must be signed in to change notification settings - Fork 428
Redirect stdin stdout
Arthur Sonzogni edited this page Aug 19, 2023
·
1 revision
FTXUI communicates with the terminal using stdout / stdin. It means if you redirect one of them toward a file or another application, then the UI will be read/written directly into them!
It exist some platform specific ways (Linux) to redirect back stdout/stdint toward the terminal:
#include <unistd.h> // dup
#include <fcntl.h> // fileno
#include <cstdio> // freopen
[...]
// Backup the current file descriptor for stdin/stdout
auto old_stdout = dup(fileno(stdout));
auto old_stdin = dup(fileno(stdin));
// Reroute stdin and stdout toward the console.
stdin = freopen("/dev/tty", "r", stdin);
stdout = freopen("/dev/tty", "w", stdout);