1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-26 05:00:28 +02:00

Allows modification of shell used by open-pipe

open-pipe executes a shell command in a subprocess. This commit adds
the ability to modify the shell used for executing commands.
The default "/bin/sh -c" can be inspected and modified by the
new procedure-with-setter 'pipe-shell-command-transformer'.

This useful in MinGW since its "sh" is not in "/bin".

* module/ice-9/popen.scm (%command-transformer): new procedure
  (pipe-shell-command-transformer): new procedure-with-setter
  (open-pipe): use new command transformer
* doc/ref/posix.texi (open-pipe): mention pipe-shell-command-transformer
  (pipe-shell-command-transformer): document new procedure
* test-suite/tests/popen.test ("pipe-shell-command-transformer"): new tests
  Also, modify open-pipe shell for MinGW
* NEWS: updated
* test-suite/tests/ports.test (mingw?): new variable
    Also, modify open-pipe shell for MinGW
This commit is contained in:
Michael Gran 2023-06-25 07:57:18 -07:00
parent 9d625278f7
commit 1174e1eb9d
5 changed files with 83 additions and 9 deletions

View file

@ -2481,7 +2481,8 @@ module@footnote{This module is only available on systems where the
Execute a command in a subprocess, with a pipe to it or from it, or
with pipes in both directions.
@code{open-pipe} runs the shell @var{command} using @samp{/bin/sh -c}.
@code{open-pipe} runs the shell @var{command} using the shell.
By default, it uses @samp{/bin/sh -c}.
@code{open-pipe*} executes @var{prog} directly, with the optional
@var{args} arguments (all strings).
@ -2489,6 +2490,9 @@ with pipes in both directions.
an input pipe, ie.@: to read from the subprocess. @code{OPEN_WRITE}
is an output pipe, ie.@: to write to it.
The default shell command that @code{open-pipe} uses can be
modified with @code{pipe-shell-command-transformer}.
@defvar OPEN_READ
@defvarx OPEN_WRITE
@defvarx OPEN_BOTH
@ -2512,6 +2516,23 @@ buffering (@pxref{Buffering}), which will be enough for small writes,
but not for say putting a big file through a filter.
@end deffn
@deffn {Scheme Procedure} pipe-shell-command-transformer
When executed with no arguments, this returns the procedure that
@code{open-pipe} uses to convert its command string argument into the
program arguments to be executed. By default, it is a function that
takes a string and returns a list that begins with @code{"/bin/sh"
"-c"}.
This procedure-with-modifier can be @code{set!}. For example, to change
the pipe shell from @code{sh} to @code{bash}, one can do the following:
@lisp
(set! (pipe-shell-command-transformer)
(lambda (cmd)
(list "/bin/bash" "-c" cmd)))
@end lisp
@end deffn
@deffn {Scheme Procedure} open-input-pipe command
Equivalent to @code{open-pipe} with mode @code{OPEN_READ}.