Description Usage Arguments Details Note Examples
Opens a set of pipes to stdin, stdout and stderr on the specified process.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | pstream(command, args = "", read_formatter = function(x) x,
write_formatter = function(x) as.character(x), bufsz = 1024,
max_reads = 1024)
set_read_formatter(stream, func)
set_write_formatter(stream, func)
set_buffer_size(stream, bufsz)
set_max_reads(stream, max_reads)
pstream_close(stream, wait = 10)
## S3 method for class 'pstream'
close(con, ...)
## S3 method for class 'pstream'
open(con, ...)
send_eof(stream)
signal(stream, signal = 15, group = FALSE)
|
command |
the program to run |
args |
a vector of argument strings |
read_formatter |
formatter function when reading |
write_formatter |
formatter function when writing |
bufsz |
size of the read buffer |
max_reads |
maximum number of buffer fills |
stream |
a pstream object |
func |
a formatter function |
wait |
number of seconds to wait before sending the kill signal |
con |
a pstream object |
... |
ignored |
signal |
the POSIX signal number (see |
group |
signal the entire process group? |
Closing a stream will wait until the spawned process completes. This
can hang your session if the process is not well-behaved. You should manually
end the proces if possible. pstream_close
will check whether the program
has exited. If it is still running, EOF is sent. The process is then
checked for wait
seconds.
If the process does not exit during that period, then SIGTERM signal is sent. If
after another round of waiting, the process has not existed, it is then sent
the SIGKILL signal. After that, the stream is manually closed.
Pipe stream objects are not compatible with R connection
objects. (See pstream_input_con
.) However, open
and close
methods are defined for convenience.
close
calls pstream_close
. open
will
reopen a closed pstream object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | x = pstream("R")
status(x)
read_stderr(x)
pstream_close(x)
x = pstream("R", "--vanilla")
read_stdout(x)
write_stdin(x, "R.Version()[[1]]")
read_stdout(x)
send_eof(x); Sys.sleep(1)
status(x)
x = pstream("R", "--vanilla")
status(x)
signal(x); Sys.sleep(1)
status(x)
x = pstream("R", "--vanilla")
status(x)
close(x)
status(x)
wf = function(x) "dir()"
rf = function(x) "Boo!"
x = pstream("R", "--vanilla --slave", rf, wf)
write_stdin(x, "q()")
read_stdout(x)
close(x)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.