call-with-input-pipe, call-with-output-pipe: allow list argument

Ivan Shmakov <[email protected]>
Newsgroups gmane.lisp.scheme.scheme48
Message-ID <[email protected]>
	The current implementation of both call-with-input-pipe and
	call-with-output-pipe uses /bin/sh to start the program
	specified, just like the system () call:

scheme48-99fb63e0ed13c-1/ $ nl -ba scheme/misc/pipe.scm
...
    29		       (lambda ()
    30			 (if input?
    31			     (remap-file-descriptors! (current-input-port)
    32						      output-pipe
    33						      (current-error-port))
    34			     (remap-file-descriptors! input-pipe
    35						      (current-output-port)
    36						      (current-error-port)))
    37			 (exec-file "/bin/sh" "-c" command))
    38		       (lambda ()
    39			 (exit 1)))))))))
scheme48-99fb63e0ed13c-1/ $ 

	Since it may be cumbersome to do all the shell quoting
	necessary, may I suggest to extend call-with-input-pipe and
	call-with-output-pipe to accept a list argument to be passed
	directly to exec?  Like:

foo> ,config ,load =scheme48/misc/packages.scm 
foo> ,open call-with-mumble-pipes 
foo> (call-with-input-pipe '("sha1sum" "--" "/dev/null") read-all)
"da39a3ee5e6b4b0d3255bfef95601890afd80709  /dev/null\n"
foo> 

	The change is as follows:

Extend `call-with-mumble-pipe' to allow list as an argument.
(call-with-mumble-pipe): Extended to accept a list argument to be passed
directly to `exec', instead of going through `/bin/sh'.

diff -r 99fb63e0ed13 scheme/misc/pipe.scm
--- a/scheme/misc/pipe.scm	Sun Oct 19 21:08:43 2008 +0200
+++ b/scheme/misc/pipe.scm	Tue Oct 21 00:14:14 2008 +0700
@@ -34,7 +34,11 @@
 		     (remap-file-descriptors! input-pipe
 					      (current-output-port)
 					      (current-error-port)))
-		 (exec-file "/bin/sh" "-c" command))
+		 (cond ((list? command)
+			(apply exec command))
+		       (else
+			;; FIXME: consider using "$SHELL" here
+			(exec-file "/bin/sh" "-c" command))))
 	       (lambda ()
 		 (exit 1)))))))))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.