Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a pipe in XP 1

Status
Not open for further replies.

PedalSteel

Programmer
May 6, 2007
118
GB
How can a Rexx program read information piped from a Windows XP command? Is it possible?

I mean something like
Code:
dir *.jpg | myprog.rex

If reading a pipe isn't possible, I guess a virtual disk might be the answer (I want to avoid disk i/o). Can someone recommend a download for that purpose? I've tried VDK, but I can't understand how to use it from the information supplied with it.

__________________________________________________
Nikon D100 RawShooter PaintShopProXI Python ReXX MySQL
 
OK. My other brain-cell kicked in and came up with the obvious answer, namely parse pull blahblah. Doh.

Which brings up another problem. The queued() function always returns 0. Is this another doh?

I'm using ooRexx from SourceForge.

____________________________________________________
Nikon D200 RawShooter PaintShopProXI Python ooReXX MySQL
 

'queued()' only returns '0' if there's nothing queued. If something is queued, queued() returns the number of lines in the queue. Try:
Code:
address TSO
queue 'a line in the outer stack'
say queued()
"NEWSTACK"
queue 'stuff'
queue 'stuff' 
queue 'more stuff'
say queued()
"DELSTACK"
say queued()
You should get
Code:
>>> 1
>>> 3
>>> 1

Frank Clarke
Tampa Area REXX Programmers' Alliance
REXX Language Assn Listmaster
 
> 'queued()' only returns '0' if there's nothing queued. If something is queued, queued() returns the number of lines in the queue.

That's what I thought, Frank, until I tried it in XP. (I don't have TSO on this laptop, I'm afraid. Crikey -- I don't even have CMS!)

Here's my pipex program . . .
Code:
/* */
trace 'n'

say queued()

zz='x'
do while zz<>''
 parse pull zz
 say '{'zz'}'
end

exit
And here are the results . . .
Code:
c:\>dir r*
 Volume in drive C is HP_MAIN
 Volume Serial Number is 58A2-DF08

 Directory of c:\

01/06/2007  16:11    <DIR>          racing
29/04/2007  15:06    <DIR>          rexxsql
03/03/2007  09:48    <DIR>          root00
25/02/2007  10:46    <DIR>          reference
               0 File(s)              0 bytes
               4 Dir(s)  37,973,966,848 bytes free

c:\>dir r* | rexx c:\exec\pipex.rex
0
{ Volume in drive C is HP_MAIN}
{ Volume Serial Number is 58A2-DF08}
{}

c:\>echo "blah blahblah blah" | rexx c:\exec\pipex.rex
0
{"blah blahblah blah" }
{}

c:\>
Note that the queue is said to be 0 in both cases. In the first it should be 11, yet 3 lines get pulled. In the second it should be 1, yet 2 get pulled. it's a mystery to me, and I find it hard to believe that it's a bug in ooRexx, which has a venerable history and an impecabble IBM provenance.



____________________________________________________
Nikon D200 RawShooter PaintShopProXI Python ooReXX MySQL
 

Maybe I'm just missing it, but I don't see any queue orders. What do you suppose is loading the queue such that 'queued()' might find something there?



Frank Clarke
Tampa Area REXX Programmers' Alliance
REXX Language Assn Listmaster
 
> What do you suppose is loading the queue such that 'queued()' might find something there?

Good question, Frank. Something is clearly producing stuff that parse pull is finding, even though queued() detects nothing.

I don't know much about pipes in Windoze, but it would appear to be the pipe symbol, namely "|", that is doing it.
Code:
dir r* | rexx c:\exec\pipex.rex
To be honest, I don't really know what is going on, but I dearly wish I did.

____________________________________________________
Nikon D200 RawShooter PaintShopProXI Python ooReXX MySQL
 
LINES() -> 1 /* data remains in the default input stream
STDIN: */

change
say queued() to say lines()
do while zz<>'' to do while lines()= 1
and try again

 
> do while lines()= 1

Thank you, RxUsr. Combining your answer with linein() does the trick. (But I'd say do while lines().)

Which still leaves the question, why did my original code partially work?

Why did it work at all?

Why should parse pull work when queued() says the queue is empty?

Is there another -- hidden -- queue in this mystery?

Will I ever run out of pithy questions?

____________________________________________________
Nikon D200 RawShooter PaintShopProXI Python ooReXX MySQL
 
Your pipe of Dir to your rexx went to STDIN not to QUEUE.
That's why Queued() = 0.
Your original routine worked because you were getting data from STDIN not the Queue.
 
> Your original routine worked because you were getting data from STDIN not the Queue.

Right. I get it now. If the queue is empty, PULL pulls lines from STDIN, which is what the Ref manual does indeed say.

Further investigation seems to show that if a pipe has been opened, PULL doesn't attempt to pull from the keyboard when there's nothing left in the pipe. It just pulls nothing from the empty pipe. But I'm rambling. Thanks again.

____________________________________________________
Nikon D200 RawShooter PaintShopProXI Python ooReXX MySQL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top