Opening a new terminal window(GCC termios)

Howdy folks!

New to this forum and this is my 1st thread so bear with me.

I have a program that prints the Fibonacci numbers by an unsigned integer given at the command line staring from 0 to n. So what I seek to do is to open a new gnome-terminal shell window and print the out put in that new terminal window. Now it uses the fork() function to start a new process but is there another way to open a terminal window besides the System() function?

What I've been trying is:

int exit_status = system("gnome-terminal")


This opens a new terminal window alright but using a pipe to write the output in terminal doesn't work: That is, the output is displayed in the command terminal that I typed the execution command.

So how do I used termios struct to create a new terminal window, open it, and then get the handle to send output to it?
Might try something like: http://cboard.cprogramming.com/cplusplus-programming/114976-redirect-ouput-another-instance-terminal-window.html

It's kind of weird behavior. Not going to work in a non-graphical environment. I would rather just send output to a log file.
Last edited on
I like helios's solution -- start a new process and pipe to it to use it's terminal.

His version is for Windows:
http://www.cplusplus.com/forum/lounge/17371/

But the concept will work for *nix too. You just need to make sure that you spawn a new process that is not attached to your current terminal, but attaches to its own.

I have no idea if what I am about to say is correct or not -- but Linux boxen tend to have multiple terminals sessions available whether or not you are using X, so it might be possible to do this without X. (But why bother?)
Duoas,


I had a look at helios's solution and that uses Windows C++ code. But what about Linux?
As I said, you would have to convert his code to use *nix functions to create a new process. I haven't done it, so I don't know how.

You will have to make sure you spawn a new process, disconnect from its controlling terminal, then set it as a new session leader (man 2 setsid). On Linux, at least, you can get a new controlling terminal by opening a terminal session.

You can probably read more here
http://www.win.tue.nl/~aeb/linux/lk/lk-10.html


But... now that we've gotten this far... wouldn't it just be simpler to open a window with a text control in it, and then write to the text control? A very simple ostream class could be made to output to the control instead of the tty or a file.


Whatever the case, Good luck!
Topic archived. No new replies allowed.