EVOLUTION-MANAGER
Edit File: processx_connections.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Processx connections</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for conn_create_fd {processx}"><tr><td>conn_create_fd {processx}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Processx connections</h2> <h3>Description</h3> <p>These functions are currently experimental and will change in the future. Note that processx connections are <em>not</em> compatible with R's built-in connection system. </p> <h3>Usage</h3> <pre> conn_create_fd(fd, encoding = "", close = TRUE) conn_file_name(con) conn_create_pipepair(encoding = "", nonblocking = c(TRUE, FALSE)) conn_read_chars(con, n = -1) ## S3 method for class 'processx_connection' conn_read_chars(con, n = -1) processx_conn_read_chars(con, n = -1) conn_read_lines(con, n = -1) ## S3 method for class 'processx_connection' conn_read_lines(con, n = -1) processx_conn_read_lines(con, n = -1) conn_is_incomplete(con) ## S3 method for class 'processx_connection' conn_is_incomplete(con) processx_conn_is_incomplete(con) conn_write(con, str, sep = "\n", encoding = "") ## S3 method for class 'processx_connection' conn_write(con, str, sep = "\n", encoding = "") processx_conn_write(con, str, sep = "\n", encoding = "") conn_create_file(filename, read = NULL, write = NULL) conn_set_stdout(con, drop = TRUE) conn_set_stderr(con, drop = TRUE) conn_get_fileno(con) conn_disable_inheritance() ## S3 method for class 'processx_connection' close(con, ...) processx_conn_close(con, ...) is_valid_fd(fd) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>fd</code></td> <td> <p>Integer scalar, a Unix file descriptor.</p> </td></tr> <tr valign="top"><td><code>encoding</code></td> <td> <p>Encoding of the readable connection when reading.</p> </td></tr> <tr valign="top"><td><code>close</code></td> <td> <p>Whether to close the OS file descriptor when closing the connection. Sometimes you want to leave it open, and use it again in a <code>conn_create_fd</code> call. Encoding to re-encode <code>str</code> into when writing.</p> </td></tr> <tr valign="top"><td><code>con</code></td> <td> <p>Processx connection object.</p> </td></tr> <tr valign="top"><td><code>nonblocking</code></td> <td> <p>Whether the pipe should be non-blocking. For <code>conn_create_pipepair()</code> it must be a logical vector of length two, for both ends of the pipe.</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>Number of characters or lines to read. -1 means all available characters or lines.</p> </td></tr> <tr valign="top"><td><code>str</code></td> <td> <p>Character or raw vector to write.</p> </td></tr> <tr valign="top"><td><code>sep</code></td> <td> <p>Separator to use if <code>str</code> is a character vector. Ignored if <code>str</code> is a raw vector.</p> </td></tr> <tr valign="top"><td><code>filename</code></td> <td> <p>File name. For <code>conn_create_pipe()</code> on Windows, a <code style="white-space: pre;">\\?\pipe</code> prefix is added to this, if it does not have such a prefix. For <code>conn_create_pipe()</code> it can also be <code>NULL</code>, in which case a random file name is used via <code>tempfile()</code>.</p> </td></tr> <tr valign="top"><td><code>read</code></td> <td> <p>Whether the connection is readable.</p> </td></tr> <tr valign="top"><td><code>write</code></td> <td> <p>Whethe the connection is writeable.</p> </td></tr> <tr valign="top"><td><code>drop</code></td> <td> <p>Whether to close the original stdout/stderr, or keep it open and return a connection to it.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Extra arguments, for compatibility with the <code>close()</code> generic, currently ignored by processx.</p> </td></tr> </table> <h3>Details</h3> <p><code>conn_create_fd()</code> creates a connection from a file descriptor. </p> <p><code>conn_file_name()</code> returns the name of the file associated with the connection. For connections that do not refer to a file in the file system it returns <code>NA_character()</code>. Except for named pipes on Windows, where it returns the full name of the pipe. </p> <p><code>conn_create_pipepair()</code> creates a pair of connected connections, the first one is writeable, the second one is readable. </p> <p><code>conn_read_chars()</code> reads UTF-8 characters from the connections. If the connection itself is not UTF-8 encoded, it re-encodes it. </p> <p><code>conn_read_lines()</code> reads lines from a connection. </p> <p><code>conn_is_incomplete()</code> returns <code>FALSE</code> if the connection surely has no more data. </p> <p><code>conn_write()</code> writes a character or raw vector to the connection. It might not be able to write all bytes into the connection, in which case it returns the leftover bytes in a raw vector. Call <code>conn_write()</code> again with this raw vector. </p> <p><code>conn_create_file()</code> creates a connection to a file. </p> <p><code>conn_set_stdout()</code> set the standard output of the R process, to the specified connection. </p> <p><code>conn_set_stderr()</code> set the standard error of the R process, to the specified connection. </p> <p><code>conn_get_fileno()</code> return the integer file desciptor that belongs to the connection. </p> <p><code>conn_disable_inheritance()</code> can be called to disable the inheritance of all open handles. Call this function as soon as possible in a new process to avoid inheriting the inherited handles even further. The function is best effort to close the handles, it might still leave some handles open. It should work for <code>stdin</code>, <code>stdout</code> and <code>stderr</code>, at least. </p> <p><code>is_valid_fd()</code> returns <code>TRUE</code> if <code>fd</code> is a valid open file descriptor. You can use it to check if the R process has standard input, output or error. E.g. R processes running in GUI (like RGui) might not have any of the standard streams available. </p> <p>If a stream is redirected to the null device (e.g. in a callr subprocess), that is is still a valid file descriptor. </p> <h3>Examples</h3> <pre> is_valid_fd(0L) # stdin is_valid_fd(1L) # stdout is_valid_fd(2L) # stderr </pre> <hr /><div style="text-align: center;">[Package <em>processx</em> version 3.8.0 <a href="00Index.html">Index</a>]</div> </body></html>