OS/2, eCS & ArcaOS - Technical > Programming
[Classic Rexx] How can one pipe data to application?
Jan-Erik Lärka:
I have an urgent need to understand how to redirect instructions to a VIO/CLI application (or several) that take commands via stdin and output data to stdout. Depending on the input it exit or require more input.
I've looked at a code sample for ePDF (Print2PS) but it is designed for the oposite situation, and examples for rxu, C/C++ on OS/2 or whatever appear to be unavailable.
Yes, one can write instructions to a file and run it with something like
--- Code: ---app.exe < "file.txt"|RXQUEUE
--- End code ---
but then one must know the reply in advance or ensure to exit (even though one would like to continue in that session).
I use that approach now, but it is ugly, slow etc.
What I need can be described as redirection of stdin and stdout through the use of a (possibly named) pipe.
Remy:
Have a look on rxutilex very easy to use
Jan-Erik Lärka:
There's a text file mentioning how to call functions, but most people new to something as this need help to grasp how and why to knit this function together with that to achieve the desired result.
Example 1: "SysFileTree" was unthinkable to me to use to find or search for files when I begun to try Rexx, the function should have been named SysSearchPath, SysFindFile or something along those lines, not "...Tree", totally bonkers name.
Example 2: Pipe in, pipe out. What "end" of the pipe do one define? I want to output data as text instructions/parameters to one end of the pipe to be sent through the pipe into the application as instructions/parameters just as input by keyboard. It should not block the application that run.
Could you enlighten me how to do such things with RXUTILEX?
How to send commands to sqlite3.exe
:D
Remy:
--- Quote from: Jan-Erik Lärka on June 11, 2025, 12:44:48 pm ---There's a text file mentioning how to call functions, but most people new to something as this need help to grasp how and why to knit this function together with that to achieve the desired result.
Example 1: "SysFileTree" was unthinkable to me to use to find or search for files when I begun to try Rexx, the function should have been named SysSearchPath, SysFindFile or something along those lines, not "...Tree", totally bonkers name.
Example 2: Pipe in, pipe out. What "end" of the pipe do one define? I want to output data as text instructions/parameters to one end of the pipe to be sent through the pipe into the application as instructions/parameters just as input by keyboard. It should not block the application that run.
Could you enlighten me how to do such things with RXUTILEX?
How to send commands to sqlite3.exe
:D
--- End quote ---
I wrote quickly a few lines (not checked but should be helpfull) usable to read program outputs into a pipe (pipeout) !
--- Code: ---/* rexx cmd */
Call RxFuncAdd 'Sys2LoadFuncs','rxutilex','Sys2LoadFuncs'
Call Sys2LoadFuncs
pipe_rxutilex=rxfuncquery('Sys2CreateNamedPipe')
/* setting a few vars */
EOF1 = x2c("0D")
EOLF = x2c("0A")
/* vars used for pipe function */
pipename = '\pipe\'||'mynamedpipe' /* to always have unique pipe name, you can append clock time to a short name */
openmode = 'WIN'
pipemode = 'WTR'
instcnt = '1' /* one only for the program pipeout */
outbuf = '4096'
inbuf = '4096'
timeout = '10000'
readbufsize = '4096'
pipeway = 'I' /* I= In, O= Out, D=dual */
/* ------------------ */
If pipe_rxutilex=0 then call pipe_proc
Else exit 28
pipe_proc:
If pipe_rxutilex=0 then do
hpipe = Sys2CreateNamedPipe(pipename,outbuf,inbuf,timeout,instcnt,,pipeway,1,)
If word(Sys2CheckNamedPipe(hpipe),1)\= 0 then do
Say "Rexx Create Named Pipe failed rc: "||word(Sys2CheckNamedPipe(hpipe),1)
Ddosrc='6 0'
Call disc_closepipe
End
Else do
hpipecon = Sys2ConnectNamedPipe(hpipe)
If word(hpipecon,1)=0 then do
Say "Rxutilex Rexx Connect Named Pipe failed"
Ddosrc='6 0'
Call disc_closepipe
End
Else Say "Rxutilex Rexx Connect Named Pipe succeeded ("||hpipecon||")"
data = Sys2Read(hpipe,readbufsize)
If data\='' then Ddosrc='0 '||length(data)
Else do
Ddosrc='6 0'
Call disc_closepipe
End
'@start '||' your program and parameters '||' >'||pipename||' 2>&1' /* program started with usable pipe - pipeout example */
Call pipe_read
End
End
return
pipe_read:
Do while word(Ddosrc,1) = 0 & word(Ddosrc,2) > 0
data=translate(data,' ',EOF1||EOLF) /* or remove this line */
Select
When wordpos('your search word into the line',data)>0 then do
/* */ Say data
/* your process */
End
Otherwise
nop
End
data = Sys2Read(hpipe,readbufsize)
If data\='' then Ddosrc='0 '||length(data)
Else Ddosrc='6 0'
End
return
disc_closepipe:
dosrc = Sys2DisconnectNamedPipe(hpipe)
clrc=Sys2Close(hpipe)
exit
--- End code ---
(for pipe in, dual mode should be set, namedpipe usable for in and out and use write to the pipe to send datas to the appl) ::)
Jan-Erik Lärka:
ok, this pipe info out of the application into the script (WIN),
how do one send instructions out from the script (WIO) into the application (applications stdin)?
Navigation
[0] Message Index
[#] Next page
Go to full version