Re: c program running 2 terminal windows, how to specify in which to write?
Jens.Toerring_at_physik.fu-berlin.de
Date: 04/29/04
- Next message: Robert Smith: "Re: help with socket code"
- Previous message: Barry Margolin: "Re: c program running 2 terminal windows, how to specify in which to write?"
- In reply to: Achraf: "c program running 2 terminal windows, how to specify in which to write?"
- Next in thread: Barry Margolin: "Re: c program running 2 terminal windows, how to specify in which to write?"
- Reply: Barry Margolin: "Re: c program running 2 terminal windows, how to specify in which to write?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Apr 2004 01:38:33 GMT
Achraf <achraf123@hotmail.com> wrote:
> I have a c program under linux, while running, it opens a new terminal
> windows using a system call. I would like to display messages on both
> windows.
Just to make the terminology clear: your not using "a system call",
you seem to have called the system() function (at least as far as I
can tell from your post). system(3) is just one of a set of utility
functions (usually involving a lot of system calls to do the job).
A system call, on the other hand, is a call of a function that, more
or less directly, asks the OS to do something for you.
> But I can't find a way to specify the terminal window I want to write
> in.
> The program is for chat and I want to keep a terminal window to write
> incoming messages, and use the other one for operation like sending
> messages or viewing list of nicks in the room....
> To start the new window, i use the command:
> system("gnome-terminal");
This won't help you a lot, you just start a new terminal (into which
you can type and execuet commands from, but not much else)
> or
> popen("gnome_terminal", "w");
> but with no results!!!
popen() returns a FILE*, so, from within your program, you can send
data to it.
> but I really can't see if there is some possible way to write to it,
> all my messages keep arriving in the original window.
Messages get read by your program, but where they get displayed
depends on where your program writes them to. I only can guess
that you use printf() (or something like this) to write the
messages you read from a socket. Probably you're already on the
right track with popen(), just write the texts you want to appear
in the new terminal to the FILE* you received from the popen()
call, using fprintf() instead of printf().
Everything you write using printf() goes automatically to the
terminal you started the program from (if there's one, otherwise
things go to the bit bucket). If you want to write to some other
destination you have to use fprintf(), with the first argument
being the FILE* you want to write to - actually printf(...) is
basically just an abbreviation for writing fprintf(stdout,...).
If you not only want to write to the new terminal but also need
input from it things get a bit more complicated since with popen()
you can only either write to another program (in your case the
new terminal) or read from it, but not both at once. In that case
you will have to write something on your own. That can become a
bit more complicated, involving to create two pipes, fork(2)ing,
dup2(2)ing (take care, FILE*'s won't do there, you will have to
juggle with file descriptors, keeping the FILE*'s in the air
while doing so;-) and then exec(2)ing a new program. Afterwards
things depend a lot on what exactly are your requirements, like
when and how often you check on the pipe from the newly opened
terminal. Then things can become really interesting;-)
Regards, Jens
-- \ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de \__________________________ http://www.toerring.de
- Next message: Robert Smith: "Re: help with socket code"
- Previous message: Barry Margolin: "Re: c program running 2 terminal windows, how to specify in which to write?"
- In reply to: Achraf: "c program running 2 terminal windows, how to specify in which to write?"
- Next in thread: Barry Margolin: "Re: c program running 2 terminal windows, how to specify in which to write?"
- Reply: Barry Margolin: "Re: c program running 2 terminal windows, how to specify in which to write?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|