Getting piped input from a program that's buffering it's stdout


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting piped input from a program that's buffering it's stdout
# 8  
Old 10-04-2016
They may also write to stderr.

I stealth edited my post, read again.
# 9  
Old 10-04-2016
Nice catch. If there's a problem, the error message would be blocked, thanks.

---------- Post updated at 01:20 AM ---------- Previous update was at 01:19 AM ----------

sed has the quit on first matching line, it should not cause trouble.
# 10  
Old 10-04-2016
Does this mean you have or haven't tried sed -u?
# 11  
Old 10-04-2016
I didn't, it's
Code:
 $ time btpick audio_.
audio_1
    0.01s real     0.00s user     0.00s system

as-is

---------- Post updated at 01:25 AM ---------- Previous update was at 01:24 AM ----------

not very pretty, but must do, this time
Code:
ping="l2ping -fc1 -a "

for i in `sed -n "s/.* \($1\).*/\1/p" /etc/bluetooth/hosts`
do
        exec 2>&1
        $ping "$i" & (sleep 1; exec $ping "$i") &

done | sed -n '/.* from \(.*\) seq.* result=0 $/ {
        s//\1/p
        q
}
'

---------- Post updated at 01:41 AM ---------- Previous update was at 01:25 AM ----------

Tried it quickly, setting $i in the loop into something nonexisting, to force an error message. It all works okay, after all, without the 2>.

The interactive shell is just waiting for the script to end, and the shell running the script is non-interactive. It's children, the pingers, can freely write to stderr even when it's a terminal, they are not in background, job control-wise. Removing the redirection of the stderr, nice to not be hiding error messages.

Treppenwitz:

expect -c 'spawn prog; interact'seems to do what I was after.

Last edited by Juha Nurmela; 10-07-2016 at 02:29 PM.. Reason: slow cogs
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Seeing input that you redirect to a program on the shell

Suppose I have a program that I've written that accepts input, ie this C++ program: #include <iostream> using namespace std; int main() { cout << "Enter something:" << endl; int x; cin >> x; cout << "You entered data" << endl; } Suppose that I have a text file,... (5 Replies)
Discussion started by: Chris J
5 Replies

2. Shell Programming and Scripting

Write a shell program with input

Hi, Here is my question: I want a shell script which I name as 'del', and can be used as del(string). when run del(string), it will delete several directories at different locations in my system,like: rm -fr /lustre/fs/scratch/user/$string rm -fr /home/user/$string rm -fr... (4 Replies)
Discussion started by: 1988PF
4 Replies

3. Shell Programming and Scripting

Help with Bash piped while-read and a read user input at the same time

Hi I am new to writing script and want to use a Bash Piped while-read and read from user input. if something happens on server.log then do while loop or if something happend on user input then do while loop. Pseudocode something like: tail -n 3 -f server.log | while read serverline || read... (8 Replies)
Discussion started by: MyMorris
8 Replies

4. Programming

How to use a debugger a piped program ?

Hi, I have 1 program that writes in to the STDIN of another program as shown below. Both programs contain 4 or 5 lines & would terminate in under a second. $ driver.exe | program.exe How is that I can attach the debugger (gdb) to program.exe ? so that I can step through and see what all... (0 Replies)
Discussion started by: RipClaw
0 Replies

5. Shell Programming and Scripting

Using piped input to gzip

Can anyone tell me why does'nt the following command work? find /gfp1/home/arijit -name "*.sas7bdat" | gzip I am trying to compress all files with extension sas7bdat with gzip. It gives error message gzip: compressed data not written to a terminal. Use -f to force compression.... (5 Replies)
Discussion started by: bs0409
5 Replies

6. Shell Programming and Scripting

Shell variable to c++ program as input

I have an Shell script which has few global variables eg : range=100; echo "$range" I want to use the same variable in my C++ program for example int main() { cout << range << "\n"; } i tried using this int main(int argc, char *argv) { cout << range << "\n"; } but... (5 Replies)
Discussion started by: shashi792
5 Replies

7. Shell Programming and Scripting

Piped input to sed 's/\n/ /' doesn't remove the line breaks..

Using ls input as example.. ls | sed 's/\n/ /'outputs with line breaks, where I was expecting the \n to disappear. I've tried \r as well wondering if terminal output used different breaks. Is there a way to remove the line breaks without saving to file and then working from there? ----------... (2 Replies)
Discussion started by: davidpbrown
2 Replies

8. Programming

C++ How to use pipe() & fork() with stdin and stdout to another program

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question:... (2 Replies)
Discussion started by: vvaidyan
2 Replies

9. Windows & DOS: Issues & Discussions

Windows Buffering during playing

Hello! Will someone out there pls help in clearifying what is really wrong with my system. I use window 98 as my operating system. I am connected to a proxy server for browsing the net. Whenever l am listening to music online l have the problem of intermitted break in which the playing will... (10 Replies)
Discussion started by: kayode
10 Replies

10. Programming

C program help please! input from pipeline

I have a project where I have to use bzcat to uncompress a file and use that output as the data to run another program on. I understand that you would do (bzcat filename.bz2 ! program name) but then how do you access that data in the c program??? Please help thanks (2 Replies)
Discussion started by: kinggizmo
2 Replies
Login or Register to Ask a Question