From: Pillsy on 2 Mar 2010 09:20 On Mar 1, 9:16 am, Raymond Toy <toy.raym...(a)gmail.com> wrote: [...] > Try this one. It works for me with CMUCL; perhaps it works with SBCL. > It basically starts ls first before starting grep. Thanks, this works! Not only does it work with SBCL, with minor modifications it also works with CCL[1]. One interesting wrinkle is that this takes a really long time (one whole second) on SBCL when run through SLIME. It's orders of magnitude faster when run from an SBCL on the command line (or when used through the CCL Cocoa listener). This is disappointing, since I was hoping to put something together that would let me "live" in SLIME and SBCL instead of having to divide time between it and a terminal window. Cheers, Pillsy > (defun piping-test2 () > (let ((ls-process (run-program "/bin/ls" '() > :wait nil > :output :stream))) > (unwind-protect > (with-open-stream (s (process-output ls-process)) > (let ((grep-process (run-program "/usr/bin/grep" '("lisp") > :input s > :output :stream))) > (when grep-process > (unwind-protect > (with-open-stream (o (process-output grep-process)) > (loop > :for line := (read-line o nil nil) > :while line > :collect line)) > (process-close grep-process))))) > (when ls-process (process-close ls-process))))) [1] CCL's RUN-PROGRAM is evidently a pretty close copy of the one provided by SBCL and CMUCL.
From: Raymond Toy on 2 Mar 2010 10:21 On 3/2/10 9:20 AM, Pillsy wrote: > On Mar 1, 9:16 am, Raymond Toy <toy.raym...(a)gmail.com> wrote: > [...] >> Try this one. It works for me with CMUCL; perhaps it works with SBCL. >> It basically starts ls first before starting grep. > > Thanks, this works! Not only does it work with SBCL, with minor > modifications it also works with CCL[1]. Cool. But if you want to do pipes like this, why not just do something like (untested): (run-program "/bin/sh" '("-c" "ls | grep lisp") :output <output stream>) Ray
From: Pillsy on 2 Mar 2010 10:27
On Mar 2, 10:21 am, Raymond Toy <toy.raym...(a)gmail.com> wrote: > On 3/2/10 9:20 AM, Pillsy wrote: [...] > > Thanks, this works! Not only does it work with SBCL, with minor > > modifications it also works with CCL[1]. > Cool. > But if you want to do pipes like this, why not just do something like > (untested): > (run-program "/bin/sh" '("-c" "ls | grep lisp") :output <output stream>) That means giviing up on the possibility of sticking Lisp code into the pipeline, which is (part of) my ultimate goal here. Perhaps that's just completely unworkable though, or this is the wrong level of abstraction to attack the goal at. Cheers, Pillsy |