Getting the output seperately in 2 terminals simultaneously
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
the output comes like this and it is for infinite loop
./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
./testexe>file1
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
echo "Executing the program"
i=1
for(( ; ; ))
do
i=$i+1
awk 'NR==$i {print}' file1
done
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.
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.
Run `tail -f /tmp/file1' in the second terminal and see what happens.
`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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.