ADDED: extra_streams() option to process_create/3 - #36
Conversation
This enables the Unix-style pattern of passing additional file descriptors to child processes beyond stdin, stdout, and stderr, so that parent and child can communicate on multiple streams. For example, a Prolog program could launch a fully-interactive child process, passing stdin/stdout/stderr connected to the TTY, while reserving a separate pair of descriptors for programmatic communication with the child.
|
Thanks. Looks useful. I'm not too happy about adding features we cannot support cross-platform (Windows). There are surely some nice use cases for this. Somehow the changes blocked passing the environment though. Try e.g. ?- help(process_create). or Pushed an additional patch for the PlDoc comments. Code should use |
I'm not thrilled about it either. Weirdly, though, it's not a technical limitation but a procedural one. You can absolutely open a stream handle and let the child process inherit it, but there's no way to assign numeric values or ordering to them, which defeats the purpose of passing the descriptors in the first place. If you know of or come up with a good way to meaningfully pass handles from parent to child, I'd be delighted to implement it! |
This looks to be an existing issue with the |
Fixes the issue of process_create/3 not passing environment to child when no environment variables are specified and create mode is spawn, exposed by fixing the spawn method. Also fixes some fd collision bugs in the extra_streams() functionality, and introduces unit testing for all three process creation methods (which found the above).
This enables the Unix-style pattern of passing additional file
descriptors to child processes beyond stdin, stdout, and stderr, so that
parent and child can communicate on multiple streams. For example, a
Prolog program could launch a fully-interactive child process, passing
stdin/stdout/stderr connected to the TTY, while reserving a separate
pair of descriptors for programmatic communication with the child.
It also fixes a couple Cmake tooling errors, which prevented Prolog from
ever recognizing the availability of
posix_spawn()andpipe2().