Getting the output seperately in 2 terminals simultaneously
Hai I have written a c program
test.c Code:
#include<stdio.h> ./testexe 1 10 2 11 3 12 4 13 5 14 6 15 7 16 ...................so on; after that I am putting the output into a file by executing shell script Code:
#!/bin/bash now I need to get the values of i in one terminal like 1 2 3 4 .........so on; and I need to get values of j to be put in another terminal like 10 11 12 13 14 ...........so on; Please help me get this.(so total of 3 terminals are opened) I tried writing script for getting i values Code:
#!/bin/bash |
In one terminal you could tail the odd lines from file1, with something like:
Code:
i=0 Surelly there are clever ways... |
Mr.Cedric I tried everything.
Have you seen the c code? It is in infinite loop. I am not getting the data in the other two terminals. |
Hi.
You do not see any output because of buffering. Try adding fflush(stdout); line: Code:
#include<stdio.h> |
Dear OP, it would be great if you simply told us what do you really want to achieve with your program. I suppose it has something to do with multiple output-files (terminals, you said), but the details aren't clear.
|
The thing is it is a real time application i am designing for my college project.It is a modbus program where in my arm board can run only one program.So i am getting all the related data to my PC when i execute the program.
Here when you get the output of a program which is executed in one terminal.So I need to know whether it is possible to seperate the datas which i am without changing my Modbus program and displaying it on seperate terminals so that all the adc values are displayed in one terminal and all gas sensor values in other terminal.One more thing it should be seperate processes which are running. |
Quote:
Please help. |
The best solution would be prefixing the messages, eg:
Code:
LOG: mesurement started |
You could send one part (either i or j) to stderr(or some other file descriptor) instead of stdout. Then you'd be able to redirect the output from the separate fd's directly from the shell.
|
Quote:
|
Quote:
|
Consider your first program without 'fflush(stdout)':
Code:
$ cat test.c `stdbuf' forces your program to flush output on each newline character (`-oL' option means that output stream should be line buffered) as if you uncommented fflush() line. stdbuf only works if program uses FILE* streams (I think). |
If you truly want to send data to multiple terminals, you will have to do quite a bit of work. Most (if not all) processes have at most one controlling terminal. Similarly, most (if not all) terminals are mapped uniquely to their owner process. To put text into the terminal space of another process generally requires the cooperation of that other process. This is the premise of Interprocess Communications (IPC). A very nice primer on IPC is Beej's Guide to IPC. If this is really what you're trying to do, then I think you probably want to use message queues, as that models the producer/consumer paradigm quite well.
After having said all of that, I'm still not convinced that your question isn't actually asking something different from what you actually want. Please confirm what your vision of a 'terminal' is. If you really truly want to use terminals, you might find it easiest to use the GNU screen utility. It allows you to write to an open screen session from a shell command, using the 'stuff' option. On re-reading your requirements, I will hazard a guess that you have a program running on a single board computer, that reads data from a modbus PLC. You want to demultiplex the modbus data, and forward it to three separate applications running concurrently on some other host. For that, it would seem to indicate that you need three clients listening on three TCP ports, and the SBC application sends the data to one of the three ports depending on its nature. Does this sound something like what you're attempting. --- rod. |
All times are GMT -5. The time now is 02:55 PM. |