With your new version 8.2.1 I have been struggling with the new pipe structure for the process command.
I found something very interesting. It appears that from the newLisp program side, there are actually 2 filehandles, 1 for read, and 1 for write. From the executed process however, stdin and stdout are seen as the same pipe!
When starting a process like this:
# Start the process
(map set '(in out) (pipe))
(process "bc" in out)
...newlisp will fork itself, and then setup a popen to the BC binary. Schematically, this leads to the following result:
Code: Select all
+-----------+ in +----------------+ +--------+
| |---------+ | in&out | |
| newLisp | | forked newlisp |---------+ binary |
| |---------+ | | |
+-----------+ out +----------------+ +--------+
Code: Select all
#!/usr/bin/newlisp
#
# Start the process
(map set '(in out) (pipe))
(process "bc" in out)
# Execute calculations
(write-line "3 + 4" out)
(println (read-line in))
(write-line "2 + 4" out)
(println (read-line in))
(write-line "1 + 4" out)
(println (read-line in))
(write-line "0 + 4" out)
(println (read-line in))
(exit)
3 + 4
2 + 4
1 + 4
0 + 4
Of course this is the result! The forked newlisp will read off the pipe immediately, before the BC binary even has time to catch the input.
I experience the same problem with my GTK-server. Here, the GTK-server will print a result to the pipe, but it reads off the stdin pipe immediately after that, so it reads it's own result again. That is because stdin and stdout are in fact the same pipe.
Concluded: your "process <str> in out" cannot be used in an actual program, but only in interactive mode.....
Is there a way to work around this?
Peter