On Tue, Jul 08, 2025 at 01:59:18PM +0300, Elko Tchernev wrote:
> Do pipes in gforth work at all? (Not Gforth in pipes, that works.)

I have now documented OPEN-PIPE:

'open-pipe' ( c-addr u wfam - wfileid wior ) gforth-0.2 "open-pipe"
   c-addr u is the name/path of an OS-level program.  If wfam is 'r/o',
the standard output of the program is piped into the Gforth process and
can be read from wfileid.  If wfam is 'w/o', data written to wfileid is
piped as standard input into the program.  wior is 0 if and only if
opening the pipe succeeded.

> I'd appreciate a single working example where two gforth instances open a
> pipe and communicate through it

That would start with something like

s" gforth <command-line-parameters>" r/o open-pipe throw

for reading the standard output of the child gforth or using w/o for
writing to the standard input of the child gforth.

Let's do a simpler example:

s" cat -n" w/o open-pipe throw constant catpipe
' words catpipe outfile-execute
catpipe close-pipe throw .

> s" mkfifo /tmp/trrr" system  ok

This would be a good start for communicating between two pre-existing
instances of Gforth.  You would then open /tmp/trrr with open-file on
both sides, however.

Finally, unix/pthread.fs contains a word create_pipe that is intended
for creating a pipe to be used between threads in a single gforth
process (although you could then also fork and have two separate
gforth processes that communicate through the pipe).  For now this is
only an internal word for our multitasker, so you have to study the
source to make use of it.

- anton

Reply via email to