Reading from a file a background program writes to


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading from a file a background program writes to
# 1  
Old 10-28-2011
Reading from a file a background program writes to

Hi!

Code:
#!/usr/bin/env bash
rm tmpcomm
nc -v -u -l 444 | hexdump -b  > tmpcomm
while :
do
    read l1 < tmpcomm
    read l2 < tmpcomm
    read l3 < tmpcomm
    read l4 < tmpcomm
 
    # do something
done

I start netcat in the background and listen for an incoming conncetion. All incoming connections write exactly four lines of hexdata in the file tmpcomm.
Now I want to read these four lines out again and do something with them. If no connection is coming in, the script should block.
Especially I want something like "For every connection, do something with the input and send a message back again".

But at the moment I have an endless loop in my script Smilie
# 2  
Old 10-29-2011
One naive way is to check for the file size unless you are not truncating the file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to prevent a C++ program reading a file that is still being written to.?

Hi, Hopefully someone can help. We have a process that writes a file using Connect Direct to our local Solaris server and then our C++ program will pick up the file and process it. Unfortunately, because of the size of the file, the C++ program is processing the file before it has finished... (7 Replies)
Discussion started by: chris01010
7 Replies

2. Solaris

OpenBSM not catching all file writes

I have a custom auditing class configured for these events but it doesn't seem to be catching it when I do a "echo hey > test.txt" Any ideas on why that is? ---------- Post updated at 06:04 PM ---------- Previous update was at 05:47 PM ---------- Scratch this topic, it looks like it's because... (0 Replies)
Discussion started by: thmnetwork
0 Replies

3. Programming

Run interactive program in background and grep it

I need to run an interactive program in the background so I can grep it for specific data to use for some logic in a script. There is no quiet or background mode on the program so I plan to redirect a document with commands in it and then to grep the output. This is almost working, except... (1 Reply)
Discussion started by: doonan_79
1 Replies

4. UNIX for Dummies Questions & Answers

Cygwin not waiting for program in background (solved)

Hello, I know this isn't exactly a Unix question, but I wasn't able to find much information elsewhere. I'm trying to run a program in the background using Cygwin on a Windows machine, then use the wait command to pause before proceeding. Unfortunately, as I've confirmed using ps aux, the... (0 Replies)
Discussion started by: ocdcollector
0 Replies

5. Shell Programming and Scripting

Background program exits prematurely?

Hello! I am currently attempting to build a very, very, basic program that attempts to act like a calendar for a "server." Using this program I need to have the client program connect to the server program, have the client wait for the server to respond through a socket, then exit and the server... (2 Replies)
Discussion started by: Entelexia
2 Replies

6. Shell Programming and Scripting

How to process and run a program in the background in perl?

Hi, I have a query about processing and running Perl program at the background. I have HTML file called Userform.html which accepts input from the user. As soon as input is given the contol goes to get.cgi (get.cgi does some processing and computing tasks). Actually get .cgi takes more... (0 Replies)
Discussion started by: vanitham
0 Replies

7. Programming

Reading ELF file Symbol table of C++ program

Folks, I have some program(Test.cpp) as follows, #include<iostream> class Abc { private: int _theVar; public : int printVar(); }; int Abc :: printVar() { _theVar=10; } main() { Abc _t; (2 Replies)
Discussion started by: vinod_chitrali
2 Replies

8. Linux

Reading ELF file Symbol table of C++ program

Folks, I have some program(Test.cpp) as follows, #include<iostream> class Abc { private: int _theVar; public : int printVar(); }; int Abc :: printVar() { _theVar=10; } main() { Abc _t; (0 Replies)
Discussion started by: vinod_chitrali
0 Replies

9. Programming

Run external program in background

Hi, in my program i need to run an external program in background.I am aware that there are at least 2 alternatives for this: 1)fork+exec 2)system("program &"); I have read several posts about this,and they all tend to suggest to use fork+exec (and that's what i am doing now). I have some... (2 Replies)
Discussion started by: Zipi
2 Replies

10. UNIX for Dummies Questions & Answers

which process writes to file

Some process rewrites a file ( i'm hacked :) Can I somehow monitor which process does that? (2 Replies)
Discussion started by: hachik
2 Replies
Login or Register to Ask a Question