This is a simple variant on
write-only-1|
: Instead of routing
coprocess output directly to the output
stream of the current job, we route it
to the input stream, so that it gets
processed by the current interpreter.
In muq/srv/
create a file write-only-2
with
contents
#!/usr/local/bin/perl select( (select(STDOUT), $| = 1)[0]); for (;;) { printf "\"Loop %d\\n\" ,\n", $loop++; sleep 10; }
As before, at the unix level, do
chmod +x write-only-2
to make
the script executable.
Now, at the Muq prompt do:
root: makeSocket --> s @$s.standardInput$s.twin --> s$s.standardOutput root: [ :socket s :commandline "write-only-2|" | ]rootPopenSocket root:
You will see a sequence of lines
Loop 0 root: Loop 1 root: ...
printing out, one every ten seconds, but this time they result from the execution by the MUF interpreter of a series of lines
"Loop 0\n" , "Loop 1\n" , ...
read from the coprocess. (Since the MUF interpreter prints a new prompt after each command executed, this time you see a prompt printed after each "Loop" line.)
As before, you may close down the subprocess by doing
root: [ :socket s | ]closeSocket root:
Gory Detail:
In the example, we use
@$s.standardInput$s.twin
rather that just
@$s.standardInput
because in general
@$s.standardInput
and
@$s.standardOutput
may be equal, both pointing
to the same bidirectional stream. (This is virtually
required by the CommonLisp standard in the simple case,
since @$S.terminalIo
must be bidirectional,
and must be used by @$s.standardInput
and
@$s.standardOutput
.)
Because Muq implements bidirectional streams using two
unidirectional streams, and always indirecting all
reads through stream$s.twin
(which points to the
stream itself in unidirectional streams),
@$s.standardInput$s.twin
gives us the stream
which, when written, is guaranteed to deliver input
to the current job.
If this is confusing, just remember that writing to
@$s.standardInput$s.twin
will always send
input to the current job, whether it is using
bidirection or unidirectional message streams.
Go to the first, previous, next, last section, table of contents.