help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: While loop and stdin


From: address@hidden
Subject: Re: While loop and stdin
Date: Mon, 26 Feb 2024 03:19:35 +0100
User-agent: K-9 Mail for Android

Thanks for following up on this, clarifications are below.


>This example still confuses me, because it looks like it wants to
>close and reopen stdin repeatedly.  Or maybe the intent is "read all
>of the available data on stdin at this moment, and whenever it reaches
>a state where the next read would block, stop reading there".
>
>Or perhaps the intent is to read all of stdin one time, and reuse that
>block of data (stored in memory) on each iteration.
>
>We could write code for each of these cases, but we need to know which
>one is desired.


The third/last scenario is the closest to the original problem. I mistakenly 
thought that while+read immediately read the whole stdin and parse it line by 
line internally, so that it would be empty for the commands inside the loop.

The majn culprit for our problem was a Gnuastro program to put three separate 
grayscale image files into a single RGB file. Until now, if anything was in the 
standard input, that program would use it as the first color channel and read 
two files from the arguments. So when that program was placed within a while 
loop that got its input from stdin, it would crash (because the dimentions of 
the stdin data were mot the same as the files)

But thanks to your explanations, I modifed that program so it only reads from 
stdin when there are no file arguments given. I now see that the previous 
behavior was non-standard.

I hope this clarifies the original problem and the solution we found thanks to 
you.

Cheers,
Mohammad




reply via email to

[Prev in Thread] Current Thread [Next in Thread]