Hi Alex - just saw this. Thanks much; your example unclogs my confusion on
pipes nicely!
Onward ~cw
On Mon, Apr 22, 2013 at 3:06 PM, Alex Vondrak <ajvond...@gmail.com> wrote:
> Well, there's your problem: you don't want `run-pipeline` at all. :)
>
> IN: scratchpad "echo \"Hi\"" run-detached my-process set-global
> IN: scratchpad my-process get-global .
> T{ process
> { command "echo \"Hi\"" }
> { environment H{ } }
> { environment-mode +append-environment+ }
> { group +same-group+ }
> { status 0 }
> }
>
> `run-pipeline` is like a series of Unix pipes. So,
>
>
> { "cat log.txt" "grep error" "sort" "uniq" } run-pipeline
>
> is like typing
>
>
> $ cat log.txt | grep error | sort | uniq
>
> at a bash prompt. Except not every element of the pipeline has to be a
> process descriptor---you can insert Factor code along the way.
>
> Roughly, it works by sequentially calling `run-pipeline-element` on each
> item in your sequence. `run-pipeline-element` is defined by:
>
> IN: scratchpad \ run-pipeline-element see-methods
> USING: combinators destructors io io.pipes.private kernel
> quotations ;
> M: callable run-pipeline-element
> [
> [ [ ?reader ] [ ?writer ] bi* ] dip
> [ ( -- result ) call-effect ] curry with-streams*
> ] with-destructors ;
>
> USING: accessors destructors io.launcher io.pipes.private kernel
> ;
> M: object run-pipeline-element
> [ >process swap >>stdout swap >>stdin run-detached ]
> [ drop [ [ dispose ] when* ] bi@ ] 3bi wait-for-process ;
>
> I.e., it's already calling `run-detached` on anything in the pipeline
> that's just a process description. Otherwise, it expects a quotation that
> takes no inputs, produces one output, and then calls that quotation with
> the I/O streams rebound. E.g.,
>
> IN: scratchpad { "cat /tmp/patch" [ readln >string ] } run-pipeline .
> {
> 0
> "diff --git a/basis/prettyprint/prettyprint-tests.factor
> b/basis/prettyprint/prettyprint-tests.factor"
> }
>
> We see that the result of the first item in the pipeline is 0 (the exit
> code of cat), and the result of the second item in the pipeline the output
> from the Factor quotation, which it read from standard-input. Except that
> standard-input was bound to the output of the prior pipeline element (the
> output of cat).
>
> Hope that helps,
> --Alex Vondrak
>
--
*~ Memento Amori*
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk