Re: [Rd] pipe(): input to, and output from, a single process

2020-03-17 Thread Greg Minshall
Dirk, > Octave had this already in the 1990s, see documentation for 'popen2' here: thanks. unix that had since the 1970s... :) cheers, Greg __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel

Re: [Rd] pipe(): input to, and output from, a single process

2020-03-17 Thread Greg Minshall
Simon, > FWIW if you're on unix, you can use named pipes (fifos) for that: i've always wondered what named pipes actually were. thanks! cheers, Greg __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel

Re: [Rd] pipe(): input to, and output from, a single process

2020-03-17 Thread Greg Minshall
Gabor, thanks. yes, managing the two-way communication is always a bit error-prone, as it depends on the input/output characteristics of the two ends -- they either match, or deadlock. it's too bad if polling is always *required* -- i'd think sometimes a programmer would be happy blocking, though

Re: [Rd] pipe(): input to, and output from, a single process

2020-03-16 Thread Simon Urbanek
FWIW if you're on unix, you can use named pipes (fifos) for that: > system("mkfifo my.output") > p = pipe("sed -l s:hello:oops: > my.output", "w") > i = file("my.output", "r", blocking=FALSE, raw=TRUE) > writeLines("hello!\n", p) > flush(p) > readLines(i, 1) [1] "oops!" Cheers, Simon > On 14/0

Re: [Rd] pipe(): input to, and output from, a single process

2020-03-16 Thread Gábor Csárdi
Well, if you want blocking, you can poll with an infinite timeout. This returns if 1) there is output, 2) the process terminates, or 3) you interrupt with CTRL+C / ESC /etc. and then right after the polling, you can read the output. This still works if the process has finished already. Gabor On

Re: [Rd] pipe(): input to, and output from, a single process

2020-03-16 Thread Dirk Eddelbuettel
On 13 March 2020 at 20:26, Greg Minshall wrote: | hi. i'd like to instantiate sed(1), send it some input, and retrieve | its output, all via pipes (rather than an intermediate file). | | my sense from pipe and looking at the sources (sys-unix.c) is that is | not possible. is that true? are th

Re: [Rd] pipe(): input to, and output from, a single process

2020-03-16 Thread Ivan Krylov
On Fri, 13 Mar 2020 20:26:43 +0300 Greg Minshall wrote: > my sense from pipe and looking at the sources (sys-unix.c) is that is > not possible. is that true? are there any thoughts of providing > such a facility? Pipes (including those created by popen(3), which R pipe() uses internally) are u

Re: [Rd] pipe(): input to, and output from, a single process

2020-03-16 Thread Gábor Csárdi
I am not sure if `pipe()` works for this, but if it turns out that it does not, then you can use the processx package, e.g.: > p <- processx::process$new("sed", c("-l", "s/a/x/g"), stdin = "|", stdout = > "|") > p$write_input("foobar\n") > p$read_output() [1] "foobxr\n" The `-l` sed flag is to m

[Rd] pipe(): input to, and output from, a single process

2020-03-16 Thread Greg Minshall
hi. i'd like to instantiate sed(1), send it some input, and retrieve its output, all via pipes (rather than an intermediate file). my sense from pipe and looking at the sources (sys-unix.c) is that is not possible. is that true? are there any thoughts of providing such a facility? cheers, Greg