Fixing stdin inside a redirected loop...

  • Permalink
  • submit to reddit
  • Email
  • Follow


In this group, it is an FGA that one should so:

    commandThatGeneratesTheFilenames | while read x ...

instead of the more common:

    for i in ...

because of the problems of filenames that spaces and other weird characters.

However, one downside to the "while" method is that inside the loop,
stdin is now coming from the pipe, and commands that we execute inside
the loop, that expect a normal stdin, will misbehave.

Workarounds:
    1) append "< /dev/tty" to each command
    2) enclose the commands in parens and redirect that.  I.e.:

	commandThatGeneratesTheFilenames | while read x;do
	    (cmd1;cmd2;cmd3;...) < /dev/tty
	    done

Method 2 is nice and seems to work fine, but I am wondering if there is
any hidden cost to it and if there is any more elegant/effcient way to
do this.

-- 
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...

0
Reply gazelle 7/20/2010 12:13:50 PM

See related articles to this posting

Kenny McCormack wrote:

> In this group, it is an FGA that one should so:
> 
>     commandThatGeneratesTheFilenames | while read x ...
> 
> instead of the more common:
> 
>     for i in ...
> 
> because of the problems of filenames that spaces and other weird
> characters.
> 
> However, one downside to the "while" method is that inside the loop,
> stdin is now coming from the pipe, and commands that we execute inside
> the loop, that expect a normal stdin, will misbehave.
> 
> Workarounds:
>     1) append "< /dev/tty" to each command
>     2) enclose the commands in parens and redirect that.  I.e.:
> 
> commandThatGeneratesTheFilenames | while read x;do
> (cmd1;cmd2;cmd3;...) < /dev/tty
> done

I think (at least with bash) it's possible to use a file descriptor other 
than the standard ones, and use read -u to read from that descriptor. This 
way, standard descriptors (0, 1 and 2) inside the loop are not affected.

Something like

exec 3< <(command)

while read -u 3 line; do
  # unaffected commands here...
done

exec 3>&-


I understand it's a highly nonstandard solution, but, depending on where it 
has to run, it might be applicable.
0
Reply pk 7/20/2010 12:55:19 PM

In article <i246br$vjs$1@speranza.aioe.org>, pk  <pk@pk.invalid> wrote:
....
>I think (at least with bash) it's possible to use a file descriptor other 
>than the standard ones, and use read -u to read from that descriptor. This 
>way, standard descriptors (0, 1 and 2) inside the loop are not affected.
>
>Something like
>
>exec 3< <(command)
>
>while read -u 3 line; do
>  # unaffected commands here...
>done
>
>exec 3>&-
>
>I understand it's a highly nonstandard solution, but, depending on where it 
>has to run, it might be applicable.

Very interesting.  As readers of my posts know, I'm not a "standards
jockey", so don't take what I say next as the typical SJ jockeying...

That said,
    1) The above works if I invoke "bash" as "bash".
    2) (However) It does not work if I invoke "bash" as "sh"
    3) It doesn't work under "dash" (which is what /bin/sh on some Linux
	boxes actually is).

Anyway, as I said, it is quite intriguing.

-- 
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...

0
Reply gazelle 7/20/2010 2:12:57 PM

In article <i24at9$rc5$1@news.xmission.com>,
Kenny McCormack <gazelle@shell.xmission.com> wrote:
....
>That said,
>    1) The above works if I invoke "bash" as "bash".
>    2) (However) It does not work if I invoke "bash" as "sh"
>    3) It doesn't work under "dash" (which is what /bin/sh on some Linux
>	boxes actually is).
>
>Anyway, as I said, it is quite intriguing.

I forgot to add, the important thing, which is that your solution,
unfortunately, does not work on the targetted system (which is a Linux
system without bash - yes, they exist).  So, I am still curious about
the questions raised in the OP - is there any hidden cost (inefficiency)
to using the ()</dev/tty method, and are there any (other) alternatives?

-- 
"We should always be disposed to believe that which appears to us to be
white is really black, if the hierarchy  of the church so decides." 

    - Saint Ignatius Loyola (1491-1556) Founder of the Jesuit Order -

0
Reply gazelle 7/20/2010 2:24:37 PM

On Tue, 20 Jul 2010 14:12:57 +0000 (UTC) gazelle@shell.xmission.com (Kenny
McCormack) wrote:

> In article <i246br$vjs$1@speranza.aioe.org>, pk  <pk@pk.invalid> wrote:
> ...
> >I think (at least with bash) it's possible to use a file descriptor
> >other than the standard ones, and use read -u to read from that
> >descriptor. This way, standard descriptors (0, 1 and 2) inside the loop
> >are not affected.
> >
> >Something like
> >
> >exec 3< <(command)
> >
> >while read -u 3 line; do
> >  # unaffected commands here...
> >done
> >
> >exec 3>&-
> >
> >I understand it's a highly nonstandard solution, but, depending on where
> >it has to run, it might be applicable.
> 
> Very interesting.  As readers of my posts know, I'm not a "standards
> jockey", so don't take what I say next as the typical SJ jockeying...
> 
> That said,
>     1) The above works if I invoke "bash" as "bash".
>     2) (However) It does not work if I invoke "bash" as "sh"
>     3) It doesn't work under "dash" (which is what /bin/sh on some Linux
> 	boxes actually is).

Standards jockey or not, if that is where it has to run, you definitely need
a standard solution.

0
Reply pk 7/20/2010 5:06:56 PM

Kenny McCormack wrote:

> In this group, it is an FGA that one should so:
> 
>     commandThatGeneratesTheFilenames | while read x ...
> 
> instead of the more common:
> 
>     for i in ...
> 
> because of the problems of filenames that spaces and other weird
> characters.
> 
> However, one downside to the "while" method is that inside the loop,
> stdin is now coming from the pipe, and commands that we execute inside
> the loop, that expect a normal stdin, will misbehave.

Name one, and I am pretty sure that I can tell you the switch that will 
prevent it from considering stdin.  For example, ssh(1) has `-n'.

-- 
PointedEars
0
Reply Thomas 7/21/2010 12:14:38 AM

Kenny McCormack wrote:

> In this group, it is an FGA that one should so:
> 
>     commandThatGeneratesTheFilenames | while read x ...
> 
> instead of the more common:
> 
>     for i in ...
> 
> because of the problems of filenames that spaces and other weird
> characters.

No, the foregone assumption (FGA is not a common Usenet acronym -- shouldn't 
that be "foregone conclusion" anyway?) is that find(1) with `-exec', or 
`find' with xargs(1), are safer than both approaches.

Usenet rule of thumb: Never ask what is better; bottom line is that better 
is what works for you.  Ask instead what is more efficient aso. given a 
specific context.

-- 
PointedEars
0
Reply Thomas 7/21/2010 12:24:50 AM

In article <i243tu$l8g$1@news.xmission.com>,
Kenny McCormack <gazelle@shell.xmission.com> wrote:
>In this group, it is an FGA that one should so:
>
>    commandThatGeneratesTheFilenames | while read x ...
>
>instead of the more common:
>
>    for i in ...
>
>because of the problems of filenames that spaces and other weird characters.
>
>However, one downside to the "while" method is that inside the loop,
>stdin is now coming from the pipe, and commands that we execute inside
>the loop, that expect a normal stdin, will misbehave.
>
>Workarounds:
>    1) append "< /dev/tty" to each command
>    2) enclose the commands in parens and redirect that.  I.e.:
>
>	commandThatGeneratesTheFilenames | while read x;do
>	    (cmd1;cmd2;cmd3;...) < /dev/tty
>	    done
>
>Method 2 is nice and seems to work fine, but I am wondering if there is
>any hidden cost to it and if there is any more elegant/effcient way to
>do this.

    Unless you specifically want to read from the controlling tty rather than
    the standard input, it's always better to save the standard input to
    another fd and then read from it.

    {
	commandThatGeneratesTheFilenames |
	    while read x <&4; do
		cmd1
		cmd2
		cmd3
	    done 4<&0 0<&3
    } 3<&0

    In modern shells (ksh93/bash/zsh) you can do:

    while read -u3 x; do
	cmd1
	cmd2
	cmd3
    done 3< <(commandThatGeneratesTheFilenames)

	John
-- 
John DuBois  spcecdt@armory.com  KC6QKZ/AE  http://www.armory.com/~spcecdt/
0
Reply spcecdt 7/21/2010 4:56:01 PM

In article <B_qdnbdAifw8u9rRnZ2dnUVZ_s6dnZ2d@speakeasy.net>,
John DuBois <spcecdt@armory.com> wrote:
....
>    Unless you specifically want to read from the controlling tty rather than
>    the standard input, it's always better to save the standard input to
>    another fd and then read from it.
>
>    {
>	commandThatGeneratesTheFilenames |
>	    while read x <&4; do
>		cmd1
>		cmd2
>		cmd3
>	    done 4<&0 0<&3
>    } 3<&0

What's the difference between enclosing the cmds in {} vs. ()?

-- 
Faced with the choice between changing one's mind and proving that there is
no need to do so, almost everyone gets busy on the proof. 

    - John Kenneth Galbraith -

0
Reply gazelle 7/21/2010 5:45:28 PM

On 2010-07-21, Kenny McCormack wrote:
> In article <B_qdnbdAifw8u9rRnZ2dnUVZ_s6dnZ2d@speakeasy.net>,
> John DuBois <spcecdt@armory.com> wrote:
> ...
>>    Unless you specifically want to read from the controlling tty rather than
>>    the standard input, it's always better to save the standard input to
>>    another fd and then read from it.
>>
>>    {
>>	commandThatGeneratesTheFilenames |
>>	    while read x <&4; do
>>		cmd1
>>		cmd2
>>		cmd3
>>	    done 4<&0 0<&3
>>    } 3<&0
>
> What's the difference between enclosing the cmds in {} vs. ()?

   Commands in ( ) are executed in a subshell.


-- 
   Chris F.A. Johnson, author           <http://shell.cfajohnson.com/>
   ===================================================================
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)

0
Reply Chris 7/21/2010 7:05:00 PM

In article <8aoumsFvcrU2@mid.individual.net>,
Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>On 2010-07-21, Kenny McCormack wrote:
>> In article <B_qdnbdAifw8u9rRnZ2dnUVZ_s6dnZ2d@speakeasy.net>,
>> John DuBois <spcecdt@armory.com> wrote:
>> ...
>>>    Unless you specifically want to read from the controlling tty rather than
>>>    the standard input, it's always better to save the standard input to
>>>    another fd and then read from it.
>>>
>>>    {
>>>	commandThatGeneratesTheFilenames |
>>>	    while read x <&4; do
>>>		cmd1
>>>		cmd2
>>>		cmd3
>>>	    done 4<&0 0<&3
>>>    } 3<&0
>>
>> What's the difference between enclosing the cmds in {} vs. ()?
>
>   Commands in ( ) are executed in a subshell.

That's what I thought.  So, the answer to the original question, despite
all the other flurry, is simply: Yes, you should use {} rather than ().

-- 
"We should always be disposed to believe that which appears to us to be
white is really black, if the hierarchy  of the church so decides." 

    - Saint Ignatius Loyola (1491-1556) Founder of the Jesuit Order -

0
Reply gazelle 7/21/2010 7:10:05 PM

Kenny McCormack wrote:

> Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>> On 2010-07-21, Kenny McCormack wrote:
>>> What's the difference between enclosing the cmds in {} vs. ()?
>>   Commands in ( ) are executed in a subshell.
> 
> That's what I thought.  So, the answer to the original question, despite
> all the other flurry, is simply: Yes, you should use {} rather than ().

No, the answer simply is, again, "it depends."  That is the part of software 
development that you do not seem to understand.

-- 
PointedEars
0
Reply Thomas 7/21/2010 8:59:14 PM

On 2010-07-21, John DuBois wrote:
> In article <i243tu$l8g$1@news.xmission.com>,
> Kenny McCormack <gazelle@shell.xmission.com> wrote:
>>In this group, it is an FGA that one should so:
>>
>>    commandThatGeneratesTheFilenames | while read x ...
>>
>>instead of the more common:
>>
>>    for i in ...
>>
>>because of the problems of filenames that spaces and other weird characters.
>>
>>However, one downside to the "while" method is that inside the loop,
>>stdin is now coming from the pipe, and commands that we execute inside
>>the loop, that expect a normal stdin, will misbehave.
>>
>>Workarounds:
>>    1) append "< /dev/tty" to each command
>>    2) enclose the commands in parens and redirect that.  I.e.:
>>
>>	commandThatGeneratesTheFilenames | while read x;do
>>	    (cmd1;cmd2;cmd3;...) < /dev/tty
>>	    done
>>
>>Method 2 is nice and seems to work fine, but I am wondering if there is
>>any hidden cost to it and if there is any more elegant/effcient way to
>>do this.
>
>     Unless you specifically want to read from the controlling tty rather than
>     the standard input, it's always better to save the standard input to
>     another fd and then read from it.

   Why?

>     {
> 	commandThatGeneratesTheFilenames |
> 	    while read x <&4; do

   That will fail on filenames beginning or ending with spaces.

while IFS= read -r x <&4

> 		cmd1
> 		cmd2
> 		cmd3
> 	    done 4<&0 0<&3
>     } 3<&0
>
>     In modern shells (ksh93/bash/zsh) you can do:
>
>     while read -u3 x; do
> 	cmd1
> 	cmd2
> 	cmd3
>     done 3< <(commandThatGeneratesTheFilenames)
>
> 	John


-- 
   Chris F.A. Johnson, author           <http://shell.cfajohnson.com/>
   ===================================================================
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)

0
Reply Chris 7/21/2010 9:30:36 PM

In article <4540035.MirdbgypaU@PointedEars.de>,
Thomas 'PointedEars' Lahn  <usenet@PointedEars.de> wrote:
>Kenny McCormack wrote:
>
>> Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>>> On 2010-07-21, Kenny McCormack wrote:
>>>> What's the difference between enclosing the cmds in {} vs. ()?
>>>   Commands in ( ) are executed in a subshell.
>> 
>> That's what I thought.  So, the answer to the original question, despite
>> all the other flurry, is simply: Yes, you should use {} rather than ().
>
>No, the answer simply is, again, "it depends."  That is the part of software 
>development that you do not seem to understand.

You funny.

(And I've not even seen any pix of you and you funny ears!)

-- 
> No, I haven't, that's why I'm asking questions. If you won't help me,
> why don't you just go find your lost manhood elsewhere.

CLC in a nutshell.

0
Reply gazelle 7/21/2010 9:34:20 PM

On 2010-07-21, Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
> No, the foregone assumption (FGA is not a common Usenet acronym

"Frequently Given Answer", used by some guy whose name I've forgotten
to refer to things he maintains in a format chosen to prevent people from
rebutting the idiocy therein.

-s
-- 
Copyright 2010, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
0
Reply Seebs 7/21/2010 9:49:57 PM

Kenny McCormack wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Kenny McCormack wrote:
>>> Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>>>> On 2010-07-21, Kenny McCormack wrote:
>>>>> What's the difference between enclosing the cmds in {} vs. ()?
>>>>   Commands in ( ) are executed in a subshell.
>>> That's what I thought.  So, the answer to the original question, despite
>>> all the other flurry, is simply: Yes, you should use {} rather than ().
>> No, the answer simply is, again, "it depends."  That is the part of
>> software development that you do not seem to understand.
> 
> You funny.

It was not my intention to amuse you, but to make you think twice.  BTW, in 
responding like this you are also making a fool of yourself with regard to 
grammar.

> (And I've not even seen any pix of you and you funny ears!)
 
I have not seen a photo of you either.  So what?
-- 
PointedEars
0
Reply Thomas 7/22/2010 12:31:09 AM

Seebs wrote:

> Thomas 'PointedEars' Lahn wrote:
>> No, the foregone assumption (FGA is not a common Usenet acronym
> 
> "Frequently Given Answer", used by some guy whose name I've forgotten
> to refer to things he maintains in a format chosen to prevent people from
> rebutting the idiocy therein.

Thanks.  In ten years of regular Usenet participation, in and outside of the 
Big 8, I had never come across that acronym.  It is not in the Jargon File 
either.  So I doubt it is more than his original research.

-- 
PointedEars
0
Reply Thomas 7/22/2010 9:44:28 AM

In article <8ap77sFvcrU3@mid.individual.net>,
Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>On 2010-07-21, John DuBois wrote:
>> In article <i243tu$l8g$1@news.xmission.com>,
>> Kenny McCormack <gazelle@shell.xmission.com> wrote:
>>>Workarounds:
>>>    1) append "< /dev/tty" to each command
>>>    2) enclose the commands in parens and redirect that.  I.e.:
>>>
>>>	commandThatGeneratesTheFilenames | while read x;do
>>>	    (cmd1;cmd2;cmd3;...) < /dev/tty
>>>	    done
>>>
>>>Method 2 is nice and seems to work fine, but I am wondering if there is
>>>any hidden cost to it and if there is any more elegant/effcient way to
>>>do this.
>>
>>     Unless you specifically want to read from the controlling tty rather than
>>     the standard input, it's always better to save the standard input to
>>     another fd and then read from it.
>
>   Why?

Because the standard input may not be the controlling tty (if the program is
piped or redirected into, or started from an environment with no controlling
tty, etc).

	John
-- 
John DuBois  spcecdt@armory.com  KC6QKZ/AE  http://www.armory.com/~spcecdt/
0
Reply spcecdt 7/22/2010 3:03:54 PM

2010-07-20, 12:13(+00), Kenny McCormack:
> In this group, it is an FGA that one should so:
>
>     commandThatGeneratesTheFilenames | while read x ...
>
> instead of the more common:
>
>     for i in ...
>
> because of the problems of filenames that spaces and other weird characters.

After

IFS='
' # NL
set -f
for i in $(commandThatGeneratesTheFilenames); do...

shouldn't be a problem (except that the loop only starts when
commandThatGeneratesTheFilenames finishes).

Other solution (not any better either than the ones that have
already been given):

while IFS= read <&3 -r i; do
   ...
done 3<<EOF
$(commandThatGeneratesTheFilenames)
EOF

{
  commandThatGeneratesTheFilenames |
    while IFS= read <&3 -r i; do
      ...
    done 3<&0 <&4 4<&-
} 4<&0

as already given would be the best one. If you're picky, you may
write it:

{
  commandThatGeneratesTheFilenames 4<&- |
    while IFS= read <&3 -r i; do
    {
      ...
    } 3<&-
    done 3<&0 <&4 4<&-
} 4<&0

or:

{
  commandThatGeneratesTheFilenames 4<&- |
    while IFS= read -r i 4<&-; do
    {
      ...
    } <&4 4<&-
    done
} 4<&0

-- 
Stephane
0
Reply Stephane 7/26/2010 4:57:51 PM
comp.unix.shell 14986 articles. 25 followers. Post

18 Replies
2708 Views

Similar Articles

[PageSpeed] 23

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

while loop inside a for loop
Hi, can someone please tell me why "time" (t) is not updated correctly within the while loop? Please run this small code in your machine and you'll know what I'm taking about. What I want is: for t=1 run the "while loop" until iq<=(numberc-1) then t=2 run the "while loop" again until iq<=(numberc-1), and so on. Basically, this code runs through all the nonzero elements of A and attempts to divide them individually into two, once a certain time has passed. Please feel free to ask for clarifications. Many thanks in advance. A=[0 0 0 0 0 0 ...

Triple nested loop python (While loop insde of for loop inside of while loop)
try to make my triple nested loop working. My code would be: c = 4 y1 = [] m1 = [] std1 = [] while c <24: c = c + 1 a = [] f.seek(0,0) for columns in ( raw.strip().split() for raw in f ): a.append(columns[c]) x = np.array(a, float) not_nan = np.logical_not(np.isnan(x)) indices = np.arange(len(x)) interp = interp1d(indices[not_nan], x[not_nan], kind = 'nearest') p = interp(indices) N = len(p) dt ...

Re: i am having a problem with while loops, i have two while loops, i have a random number generator inside the &quot;inside&quot; loop and i want to read an array outside the &quot;outer&quot;
I think I have a similar problem - I have a while loop with Flat Sequence controlled for loop that produces output. This output needs to be displayed every while loop pass, but I get no output as the while loop feeds back thru a shift register and repeats all the innner funcions without sending the ouput to form new entries in the array. &nbsp; Is there any way we could stop the while loop for a split second (but practically just for no time, so that no time is wasted when it outputs the data)? &nbsp; Or is it a bad approach altogether? &nbsp; Appreciate any advice. &nbsp; kolo...

Re: i am having a problem with while loops, i have two while loops, i have a random number generator inside the &quot;inside&quot; loop and i want to read an array outside the &quot;outer&quot; #2
Hi guys, Apologies about he messy thread - I needed asolution urgently and I didn't get a chance to notice the post date. &nbsp; :Ravens - Thank you a lot. The solution, also found in "my assignmnet live update.vi", works perfectly, doing exactly what I needed. Thanks again. kolorek ...

Nested While loop inside For loop
I have been coding in matlab for a while and I am confused about the below code: It seems like the "For loop" iterator variable "Index" does not update inside the "While loop". Please help me understand! I hate to assume this is some error induced on Matlab's end. ---------- CODE ------------ for Index = 390000:length(Stopxy) fprintf('Index: %d, \n',Index); while (Stopxy_YCoord(Index) < LowToHighThresh) fprintf('Index: %d, Yval: %f \n',Index,Stopxy_YCoord(Index)); Stopxy_YCoord(Index); Index = Index + 1; ...

Ending a while loop inside a while loop
How do I make a while loop run as long as the while loop that contains it is running? I tried wiring both conditional terminals to a stop button in the outer loop, but that doesnt seem to work? Is there another way? &nbsp; Thanks. It doesn't work because of data dependency. Once you are inside the inner loop the outer loop will not go to the next iteration until the inner loop is done. It sounds to me like you want parallel loops running, rather than one inside the other. If you open the Example Finder (Help -&gt; Find Examples), and search for "loops", open the examples...

timed loop inside a while loop
Hi all, I want to ask if I have a timed loop inside a&nbsp; while loop ,&nbsp; the timed loop&nbsp; does a certain task &nbsp;a 100 iteration ( each time loop iteration is 2 second duration)&nbsp;each while loop iteration &nbsp;, at each&nbsp; while loop iteration the time loop writes the actual time spent to a text file for this certain task. &nbsp; for the next while loop, the timed loop contiues&nbsp; to write the time spent from the previous while loop ( ex the first while loop the time loop ends the last results with 200 second for a 100&nbsp; time ...

Loop with 2 loops. Start 2 'inside' loops at different time.
Hello, &nbsp; I've got a question. Is there a technique or a certain road which will provides the following... I have a while loop. In that while loop I have some other while loops. Now I want to start the while loops in the big loop at differents time... how can I do that... &nbsp; I included the problem in the vi. When I press start for inside loop 1 I can't start inside loop 2.&nbsp; It's obvious that I can't do that because I can't iniziate a other while loop because the 'inside' loop is still running. But is there a certain technique for this? It is...

Putting the loop inside of loop properly
I just would like to make my previous question simpler and I bit adjusted m= y code with help with Ulich and Chris. The basic structure of my code is: for c in range(5,25): for columns in ( raw.strip().split() for raw in f ): a.append(columns[c]) x =3D np.array(a, float) not_nan =3D np.logical_not(np.isnan(x)) indices =3D np.arange(len(x)) interp =3D interp1d(indices[not_nan], x[not_nan], kind =3D 'nearest= ') p =3D interp(indices) N =3D len(p) fpsd =3D plot_freq*PSD ...

Simplify if statements and for loops inside for loops
Hello, I'm going for loop crazy and can't figure out how to simplify. It just keep= s getting longer and more complicated. The gist of what I'm trying to do is= match each element of mdate =3D string[14] to array adatea=3Dstring[74] (f= ind matching dates). Once I know where if any place it matches I want to se= e if criteria are met to actually use that profile. This is where I go craz= y. In some cases because there could be more than one profile on a single d= ay, index might equal more than one location. For each of those locations I= need to make sure there are at ...

break inside of case- statement inside of loop
Hi! I have some code that looks similar to this: -------------------------------------------- char array[10] = "abcdefghij"; for (int i = 0; i < 10; i++) { switch (array[i]) { case 'a': /* code */ break; case 'b': /* code */ break; case 'c': /* code */ break; default: /* code */ break; } } -------------------------------------------- Is it possible to break out of the for loop from inside of one case- statement, or do I have to use a workaround? In article <1172402165.914050@nntpcache01.si.eunet.at>, Alexan...

speed up for loop inside for loop short question
Hi there, Given three column vectors x,y,z I want to calculate the probabilities: P(X<Y<Z), P(X=Y<Z), P(X<Y=Z), P(X=Y=Z). The following code gets the job done but I would like it to be faster. Is there a way of getting rid of at least one of the for loops? (I described the problem above instead of just giving the code because it might be helpful for someone to take a completely different approach, or check me (I think this is correct). Anyway if you are bored to check, any ideas regarding the speed would be more than welcome!). Thanx in advance for any answers! o...

Radio Button Loop inside Form Element Loop
I have a for loop seen below.... var the_form = document.getElementById(formName); for(var i=0; i<the_form.length; i++) { var temp = the_form.elements[i].type; if (temp == "radio") { for (x = 0; x < the_form.elements[i].length - 1; x++) { //do stuff } } } Right before the inside loop I do the following and next to its the results, any idea why the last one returns 0? alert(the_form.elements[i].id); // returns question1 alert(the_form.question1.length); // returns 4 (amount of radio buttons in that group) alert(the_form.elements[i].length); // returns 0 I...

Error -50103 occured with timed loop inside a while loop
Hello everyone,i wrote an application to sample analog voltage from&nbsp; DAQ6024E card (see the attachments).I have a big while loop in the VI because a I want to add some other functions later.In the "WHILE_Cont Acq&amp;Graph Voltage-Int Clk.vi" I use a while loop inside the big while loop to read the samples. It's working properly. but when I use a timed loop inside the big while loop (see "TIMED_LOOP_Cont Acq&amp;Graph Voltage-Int Clk.vi"), I get an error -50103 from the timed loop.&nbsp; It seems that the first cycle is ok, but after the first cyc...

Redirect stdin ?
Hi, I have a c application (Lex&Yacc based) that parses from stdin. I want to rewrite the code a bit to allow reading the source from a char array instead from stdin without touching the lex and yacc generated source code. How could I do that ? What is about the problem when the buffer is too big to feed the source to the parser at once ? Any ideas ? Thanks, Lothar On Dec 31, 1:40 pm, Lothar Behrens <lothar.behr...@lollisoft.de> wrote: > I have a c application (Lex&Yacc based) that parses from stdin. I want > to rewrite the code > a bit to allow reading the source...

fix loop
this loop should give me for -1 0 and for 1 should give me a 1, can anyone help me. My code is at the bottom thanks p=[-1.0000 1.0000 -1.0000 -1.0000 -1.0000 -1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 -1.0000 ]; k=1; i=0; D=[]; for i=1:length(p) a=p(i); if a==-1.0000 D(1,k)=0; else D(1,k)=1; end k=k+1; end D "Omar Latif" <omar-latif@hotmail.com> wrote in message <g5tmdc$c3c $1@fred.mathworks.com>... > this loop should give me for -1 0 and for 1 should give me > a 1, can anyone help me. My code is a...

redirecting Stdin
Hi Is is Possible to redirect the Python stdin in order to receive stdin commands from a file ? The time of redirection can last until exiting the Python and should be transparent for python it self. with regards Jon Jon Arter wrote: > Is is Possible to redirect the Python stdin in order to receive stdin > commands from a file ? > The time of redirection can last until exiting the Python and should > be transparent for python it self. Sure: sys.stdin = file('newinput') -- Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/ ...

Does the value inside DO loop still accessible when control jumps out of the loop?
Hi, I am new to Fortran. I am wondering in the code below, if GOTO 106 is executed, then the value of I in line 106 is the last value in the DO loop, correct? Thank you very much. DO I = 2, 11 IF (COVER .LT. ADC(I)) GOTO 106 ENDDO WEAI = 1.0 GOTO 105 106 J = I - 1 FJ = J - 1 For some languages, ex Java, since I is local inside the loop, if jump out of it(by means of throw an Exception, say), the value of I is lost. Shawn <shaw@nospam.com> wrote: > I am new to Fortran. I am wondering in the code below, if GOTO 106 is > execut...

How to loop through a list while inside the loop, the list size may be decreased?
Hi, I have a List containing Person objects. I am going through the list using a for loop. Inside the loop, I check each Person obj, if he/she disqualifies, I want to delete the object from the list. I found that the for loop always run into out of index exception, because the list size is gradually decreased, but the for loop "remembers" the original size. for(int i=0; i < list.size(); i++) { if(..) //check { list.get(i).remove(i); //this decreases the number of objects in list, correct? } } Thank you very much. www wrote: > Hi, > > I have a List contai...

Redirecting stdin...
Hi! I'm trying to make a program wich takes stdout from one program stores it then sends that data to stdin of another program. This all works except progam 2 waits for EOF forever, or at least until I kill the process. How can I make p2 know that the file has ended. It is possible because if I do p1 params | p2 params everything works just fine. /Erik erik.brannlund_nospam_@epl.ericsson.se wrote: > I'm trying to make a program wich takes stdout from one program > stores it then sends that data to stdin of another program. This all > works except progam 2 w...

Fixed for loop
Is there a better way in C++ to make a very simple for loop look very simple? #define FOR(i, x) for(int i = 0; i < x; ++i) FOR(i,3) { // ... } -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] On Friday, June 28, 2013 8:57:42 AM UTC-5, Gon Solo wrote: > Is there a better way in C++ to make a very simple for loop look > very simple? > > #define FOR(i, x) for(int i = 0; i < x; ++i) > > FOR(i,3) { > // ... > } Define "simple". A few fe...

How to synchronise FPGA single-cycle loops with other loops inside the FPGA-VI
Hello there, i need to synchronise several while loops inside an FPGA-VI to a Single-cycle-loop. These loops need to be active for a variable amount of cycles of the single cycle loop. (In example, the single cycle loop generates a clock and&nbsp;the loops need to be active for a certain amount of clock cycles). Already tried occurences(Clock sets them, other loop counts occurences and waits till desired number is achieved)&nbsp;but they seem not to work or maybe i used them in a wrong manner. &nbsp; I hope somebody can help me with this problem. &nbsp; As an additional questi...

How do I initialize one channel of a graph outside a loop, and the other channel INSIDE the loop
I am creating a test-control VI for a motor-control test bench.&nbsp; We have predefined load-cycles that we run depending on the article under test&nbsp;and attributes we wish to "stress".&nbsp; I&nbsp;load these profiles from a&nbsp;spreadsheet (txt file). &nbsp; I want to plot the load profile on a graph...and then, once testing has started, plot a second channel that consists of a single data point (filled to zero) that updates with every second of run-time.&nbsp; This second channel results ina vertical line drawn over the load profile indicating the...

Running a sub vi inside a while loop and continuing loop execution without waiting for sub vi to complete execution
I have&nbsp;a main VI wich calls a "dialog-type" vi wich is supposed to sit and display certain information until the user closes the window.&nbsp; The main vi runs a continuous while loop, inside that loop there is a condition check, it it's true it will launch the sub vi.&nbsp; The problem is that when the sub vi is launched and active the main application sits and waits for the sub vi to finish executing and return control to it.&nbsp; I need to have the sub vi window open and still continue running the code on the main vi.&nbsp; Can anybody offer any sugge...