david135 / ypsilon

Automatically exported from code.google.com/p/ypsilon
Other
0 stars 0 forks source link

[request] Extended subprocess interface #93

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice if the subprocess interface could be extended to cover
these cases:

1) Allow choosing not to search $PATH (i.e. use execv() instead of exevp()).
2) Allow specifying the environment for the subprocess.
3) Allow using existing file handles as std{in,out,err} for the subprocess,
to allow building pipelines.

The attached patch adds a `process*' procedure with this signature:

   (process* search? env stdin stdout stderr program . args)

Here `search?' indicates wether $PATH should be searched (must be a
boolean). If `env' is #f, the environment of the parent is inherited,
otherwise it must be an alist with string keys and string values which
specifies the environment for the child process. stdin, stdout and
stderr must be either #f (in which case a pipe is created an the
associated port returned as in `process'), or a file-port to be used
for the stdin, stdout or stderr of the child. If a port is specified,
the return value of `process*' contains #f in the position where the
pipe()d port would have been returned.

The implementation in the patch is only for POSIXy platforms -- it
breaks the Windows support for both `process' and
`process*'. Additionally, the case of `search?' being #t and `env'
being non-#f is not handled as POSIX does (for whatever strange
reason) not provide an execvpe() function. This can be worked around
by emulating the semantics it should provide using exeve() -- I'll
address this in the next iteration of the patch.

Original issue reported on code.google.com by rott...@gmail.com on 15 Apr 2009 at 3:29

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you for your suggestion!
--fujita

Original comment by y.fujita...@gmail.com on 20 Apr 2009 at 11:51

GoogleCodeExporter commented 9 years ago
This is a fixed patch, the previous had a bug causing segfaults when the 
environment
alist had more than one entry; duh.

Original comment by rott...@gmail.com on 20 Apr 2009 at 12:27

Attachments:

GoogleCodeExporter commented 9 years ago
> POSIX does (for whatever strange reason) not provide an execvpe() function. 
I agree. It is strange. :(

I found 'posix_spawn' and 'posix_spawnp' can handle both 'search?' and 'env'
simultaneously. I have implemented 'process-spawn' with them. 'process-spawn' 
have
the same interface that you suggested, and it also supports Windows platform.

    (process-spawn search? env stdin stdout stderr program . args)

The svn trunk directory is updated to revision 439.
Your comments are very welcome.
Please Try! Thank you. :)

-- fujita

Original comment by y.fujita...@gmail.com on 1 May 2009 at 10:01

GoogleCodeExporter commented 9 years ago
Seems to work fine -- thanks!

Original comment by rott...@gmail.com on 6 Jun 2009 at 4:13