run_process: Asynchronous external process execution

View source: R/process.R

run_processR Documentation

Asynchronous external process execution

Description

Start an external process in the background, and report its completion via a deferred.

Usage

run_process(
  command = NULL,
  args = character(),
  error_on_status = TRUE,
  wd = NULL,
  env = NULL,
  windows_verbatim_args = FALSE,
  windows_hide_window = FALSE,
  encoding = "",
  ...
)

Arguments

command

Character scalar, the command to run. If you are running .bat or .cmd files on Windows, make sure you read the 'Batch files' section in the process manual page.

args

Character vector, arguments to the command.

error_on_status

Whether to reject the referred value if the program exits with a non-zero status.

wd

Working directory of the process. If NULL, the current working directory is used.

env

Environment variables of the child process. If NULL, the parent's environment is inherited. On Windows, many programs cannot function correctly if some environment variables are not set, so we always set HOMEDRIVE, HOMEPATH, LOGONSERVER, PATH, SYSTEMDRIVE, SYSTEMROOT, TEMP, USERDOMAIN, USERNAME, USERPROFILE and WINDIR. To append new environment variables to the ones set in the current process, specify "current" in env, without a name, and the appended ones with names. The appended ones can overwrite the current ones.

windows_verbatim_args

Whether to omit the escaping of the command and the arguments on windows. Ignored on other platforms.

windows_hide_window

Whether to hide the window of the application on windows. Ignored on other platforms.

encoding

The encoding to assume for stdout and stderr. By default the encoding of the current locale is used. Note that processx always reencodes the output of both streams in UTF-8 currently.

...

Extra arguments are passed to process$new(), see process. Note that you cannot pass stout or stderr here, because they are used internally by run(). You can use the stdout_callback, stderr_callback, etc. arguments to manage the standard output and error, or the process class directly if you need more flexibility.

Value

Deferred object.

Examples

## Not run: 
afun <- function() {
  run_process("ls", "-l")$
    then(function(x) strsplit(x$stdout, "\r?\n")[[1]])
}
synchronise(afun())

## End(Not run)

gaborcsardi/async documentation built on Nov. 20, 2024, 4:51 p.m.