system2 {base}R Documentation

Invoke a System Command

Description

system invokes the OS command specified by command.

Usage

system2(command, args = character(),
        stdout = "", stderr = "", stdin = "", input = NULL,
        env = character(),
        wait = TRUE, minimized = FALSE, invisible = TRUE)

Arguments

command the system command to be invoked, as a character string.
args a character vector of arguments to command.
stdout, stderr where output to ‘stdout’ or ‘stderr’ should be sent. Possible values are "", to the R console (the default), NULL or FALSE (discard output), TRUE (capture the output in a character vector) or a character string naming a file.
stdin should input be diverted? "" means the default, alternatively a character string naming a file. Ignored if input is supplied.
input if a character vector is supplied, this is copied one string per line to a temporary file, and the standard input of command is redirected to the file.
env character vector of name=value strings to set environment variables.
wait a logical (not NA) indicating whether the R interpreter should wait for the command to finish, or run it asynchronously. This will be ignored (and the interpreter will always wait) if stdout = TRUE.
minimized, invisible arguments that are accepted on Windows but ignored on this platform, with a warning.

Details

Unlike system, command is always quoted by shQuote.

For details of how command is found see system.

Because of the way it is implemented, on a Unix-alike stderr = TRUE implies stdout = TRUE.

Value

If stdout = TRUE or stderr = TRUE, a character vector giving the output of the command, one line per character string. (Output lines of more than 8095 bytes will be split.) If the command could not be run an R error is generated.

In other cases, the return value is an error code (0 for success), given the invisible attribute (so needs to be printed explicitly). If the command could not be run for any reason, the value is 127. Otherwise if wait = TRUE the value is the exit status returned by the command, and if wait = FALSE it is 0 (the conventional success value).

Note

system2 is the beginnings of a more portable interface than system which allows redirection of output without needing to invoke a shell on Windows. It is more flexible.

There is no guarantee that if stdout and stderr are both TRUE or the same file that the two streams will be interleaved in order. This depends on both the buffering used by the command and the OS.

See Also

system.


[Package base version 2.12.0 Index]