cancel
Showing results for 
Search instead for 
Did you mean: 

send data between two terminals

Jordan89
Occasional Visitor

send data between two terminals

Hello,

 

I'm beginner in c programming in linux.... and i have a question :

how can i make connection between two terminals ?
i've to compile 1 C file using gcc compiler and when i run the object file on the terminal (window1), a new terminal will be opened (window2)
and when i type any line of code in window2 it must executed in window1


please Help me :(
Regards,

2 REPLIES
Matti_Kurkela
Honored Contributor

Re: send data between two terminals

Normally, the "standard input" and "standard output" of a process are associated with the terminal it's started from. In other words, if you run your program in window1, its default input and output will work via window1.

 

If the program uses X11 libraries, it can certainly open a new window, although that is somewhat more complicated than just using the standard input/output... and that new window can be made to behave like a terminal to some degree, if you wish.

 

First, a bit of background:

A real X11 terminal application (like xterm/kterm/gnome-terminal or whatever) is typically started from a X11 GUI, so it might not necessarily have a standard input in the sense of command-line programs. Because the purpose of terminal applications is to allow the user to run command-line programs in a GUI environment, a terminal application must allocate and set up a pseudo-TTY device and set up an environment that is suitable for command line programs, and then start up the required command-line program (often, but not always, a shell, more specifically the user's default shell as defined in /etc/passwd) as a separate process. While the command-line program runs, the terminal application must process any terminal control character sequences sent by the command-line program and modify the output that is going to the  window appropriately.

 

When you refer to window2 as a "terminal", I guess you might mean something like a "text input window", since you apparently don't want to make it work fully like a terminal.

 

If you can run two separate commands on two terminals and the main requirement is to make them communicate with each other, this could be much easier to implement. There are many ways to make two processes communicate with each other: depending on your exact requirements, you might use shared memory, Unix sockets, or even network sockets (probably TCP).

 

Another way to make such an assignment easier would be to use a toolkit / user interface library to handle the majority of the work involved in setting up a new window and processing all the events associated with it. However, I understand most modern X toolkits/libraries (like Qt of KDE and GTK of GNOME ) use C++ instead of plain C. Whether this is school/university assignment or a real-life project, there might be some practical restrictions to your choice of UI toolkit libraries: more detailed information is required.

 

> and when i type any line of code in window2 it must executed in window1

 

Do you mean C code?

 

You should understand that C is a compiled language: individual lines of C code don't necessarily make sense alone, so they cannot be executed line by line. Instead, the whole program is converted to executable form at once (or in multiple modules, if a bigger project) by a specialized program known as a compiler.

When any kind of program code is processed line by line as soon as it is entered, the processing is done by a different kind of specialized program, known as an interpreter. A computer language that is designed to be processed by a compiler may not be optimal for an interpreter, and vice versa.

 

Designing an interpreter can be fairly advanced programming, and as you say you're a beginner, I think you are simply unaware of all the details you must solve. It seems to me that you're "trying to run before you've learned to walk": you're setting yourself a task that may be too far above your current skill level.

 

To get good answers to programming questions, you would need to describe your requirements in much more detail: your description above is so vague that it would be very difficult to give any detailed advice.

 

Depending on exact requirements, your task sounds like it might be appropriate as a "term paper" level programming assignment for a challenging "Programming 101" course at university level... or if you need to implement something close to full functionality of C,  it might be appropriate as a main assignment of an entirely separate "Interpreter Design And Implementation" course (with at least Programming 101 and 102 as mandatory pre-requisites).

 

MK
Jordan89
Occasional Visitor

Re: send data between two terminals

Hi...
Thanks for your replay... and i have to make clear two things , first thing that I'm a beginner in C programming in LINUX..And what the c code i have to write to do what i want...how to run the commands i want,,,etc.

the second thing I'm sorry when i say

> and when i type any line of code in window2 it must executed in window1

i mean...when I type a string -as a command- on window2 it must executed in window1

 

my problem..i have to write the C code,,,,and run it in linux using linux commands and function..and i dosen't have a good and strong background about linux..and i have no time :(

 

Regards,