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
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk