Author Topic: [Classic Rexx] How can one pipe data to application?  (Read 1084 times)

Jan-Erik Lärka

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 340
  • Karma: +7/-0
    • View Profile
[Classic Rexx] How can one pipe data to application?
« on: June 10, 2025, 09:15:44 pm »
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: [Select]
app.exe < "file.txt"|RXQUEUEbut 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

  • Hero Member
  • *****
  • Posts: 894
  • Karma: +14/-1
    • View Profile
Re: [Classic Rexx] How can one pipe data to application?
« Reply #1 on: June 10, 2025, 09:50:42 pm »
Have a look on rxutilex very easy to use

Jan-Erik Lärka

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 340
  • Karma: +7/-0
    • View Profile
Re: [Classic Rexx] How can one pipe data to application?
« Reply #2 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

Remy

  • Hero Member
  • *****
  • Posts: 894
  • Karma: +14/-1
    • View Profile
Re: [Classic Rexx] How can one pipe data to application?
« Reply #3 on: June 11, 2025, 02:54:57 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

I wrote quickly a few lines (not checked but should be helpfull) usable to read program outputs into a pipe (pipeout) !

Code: [Select]
/* 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

(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

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 340
  • Karma: +7/-0
    • View Profile
Re: [Classic Rexx] How can one pipe data to application?
« Reply #4 on: June 11, 2025, 04:49:36 pm »
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)?
« Last Edit: June 11, 2025, 04:53:00 pm by Jan-Erik Lärka »

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5427
  • Karma: +129/-1
    • View Profile
Re: [Classic Rexx] How can one pipe data to application?
« Reply #5 on: June 11, 2025, 05:12:59 pm »
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.

When sub-directories were first introduced, they were often described as a tree. The root (directory), branches or stems (sub-directories) and leaves (files). There were even commands such as deltree to delete multiple sub-directories in a branch.

Remy

  • Hero Member
  • *****
  • Posts: 894
  • Karma: +14/-1
    • View Profile
Re: [Classic Rexx] How can one pipe data to application?
« Reply #6 on: June 11, 2025, 06:36:59 pm »
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)?

Use the pipe as input mode too
may be specifying dual mode (I didn't have time to give it a try)+ something like <\pipe\nnnnnnn before the >\pipe\nnnnnnn and instcnt to 2!
Use the write function from rxutilex to write into the pipe

The application should support using pipe input and output.

sqlite3 seems to use special syntax
« Last Edit: June 11, 2025, 08:59:41 pm by Remy »

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5427
  • Karma: +129/-1
    • View Profile
Re: [Classic Rexx] How can one pipe data to application?
« Reply #7 on: Today at 02:39:12 am »
What about binary vs text? Often in C have to purposely set the pipe to binary, though for sending sending commands to a program it shouldn't matter.