1 2process_has_input_connection <- function(self, private) { 3 "!DEBUG process_has_input_connection `private$get_short_name()`" 4 !is.null(private$stdin_pipe) 5} 6 7process_has_output_connection <- function(self, private) { 8 "!DEBUG process_has_output_connection `private$get_short_name()`" 9 !is.null(private$stdout_pipe) 10} 11 12process_has_error_connection <- function(self, private) { 13 "!DEBUG process_has_error_connection `private$get_short_name()`" 14 !is.null(private$stderr_pipe) 15} 16 17process_has_poll_connection <- function(self, private) { 18 "!DEBUG process_has_error_connection `private$get_short_name()`" 19 !is.null(private$poll_pipe) 20} 21 22process_get_input_connection <- function(self, private) { 23 "!DEBUG process_get_input_connection `private$get_short_name()`" 24 if (!self$has_input_connection()) 25 throw(new_error("stdin is not a pipe.")) 26 private$stdin_pipe 27} 28 29process_get_output_connection <- function(self, private) { 30 "!DEBUG process_get_output_connection `private$get_short_name()`" 31 if (!self$has_output_connection()) 32 throw(new_error("stdout is not a pipe.")) 33 private$stdout_pipe 34} 35 36process_get_error_connection <- function(self, private) { 37 "!DEBUG process_get_error_connection `private$get_short_name()`" 38 if (!self$has_error_connection()) 39 throw(new_error("stderr is not a pipe.")) 40 private$stderr_pipe 41} 42 43process_get_poll_connection <- function(self, private) { 44 "!DEBUG process_get_poll_connection `private$get_short_name()`" 45 if (!self$has_poll_connection()) throw(new_error("No poll connection")) 46 private$poll_pipe 47} 48 49process_read_output <- function(self, private, n) { 50 "!DEBUG process_read_output `private$get_short_name()`" 51 con <- process_get_output_connection(self, private) 52 if (private$pty) if (poll(list(con), 0)[[1]] == "timeout") return("") 53 rethrow_call(c_processx_connection_read_chars, con, n) 54} 55 56process_read_error <- function(self, private, n) { 57 "!DEBUG process_read_error `private$get_short_name()`" 58 con <- process_get_error_connection(self, private) 59 rethrow_call(c_processx_connection_read_chars, con, n) 60 61} 62 63process_read_output_lines <- function(self, private, n) { 64 "!DEBUG process_read_output_lines `private$get_short_name()`" 65 con <- process_get_output_connection(self, private) 66 if (private$pty) { 67 throw(new_error("Cannot read lines from a pty (see manual)")) 68 } 69 rethrow_call(c_processx_connection_read_lines, con, n) 70} 71 72process_read_error_lines <- function(self, private, n) { 73 "!DEBUG process_read_error_lines `private$get_short_name()`" 74 con <- process_get_error_connection(self, private) 75 rethrow_call(c_processx_connection_read_lines, con, n) 76} 77 78process_is_incompelete_output <- function(self, private) { 79 con <- process_get_output_connection(self, private) 80 ! rethrow_call(c_processx_connection_is_eof, con) 81} 82 83process_is_incompelete_error <- function(self, private) { 84 con <- process_get_error_connection(self, private) 85 ! rethrow_call(c_processx_connection_is_eof, con) 86} 87 88process_read_all_output <- function(self, private) { 89 result <- "" 90 while (self$is_incomplete_output()) { 91 self$poll_io(-1) 92 result <- paste0(result, self$read_output()) 93 } 94 result 95} 96 97process_read_all_error <- function(self, private) { 98 result <- "" 99 while (self$is_incomplete_error()) { 100 self$poll_io(-1) 101 result <- paste0(result, self$read_error()) 102 } 103 result 104} 105 106process_read_all_output_lines <- function(self, private) { 107 results <- character() 108 while (self$is_incomplete_output()) { 109 self$poll_io(-1) 110 results <- c(results, self$read_output_lines()) 111 } 112 results 113} 114 115process_read_all_error_lines <- function(self, private) { 116 results <- character() 117 while (self$is_incomplete_error()) { 118 self$poll_io(-1) 119 results <- c(results, self$read_error_lines()) 120 } 121 results 122} 123 124process_write_input <- function(self, private, str, sep) { 125 "!DEBUG process_write_input `private$get_short_name()`" 126 con <- process_get_input_connection(self, private) 127 if (is.character(str)) { 128 pstr <- paste(str, collapse = sep) 129 str <- iconv(pstr, "", private$encoding, toRaw = TRUE)[[1]] 130 } 131 invisible(rethrow_call(c_processx_connection_write_bytes, con, str)) 132} 133 134process_get_input_file <- function(self, private) { 135 private$stdin 136} 137 138process_get_output_file <- function(self, private) { 139 private$stdout 140} 141 142process_get_error_file <- function(self, private) { 143 private$stderr 144} 145 146poll_codes <- c("nopipe", "ready", "timeout", "closed", "silent", "event") 147 148process_poll_io <- function(self, private, ms) { 149 poll(list(self), ms)[[1]] 150} 151