ID EN
System & OS

system

R Base 3.6.2

system invokes the OS command specified by command.

Syntax

R
system(command, intern = FALSE,
       ignore.stdout = FALSE, ignore.stderr = FALSE,
       wait = TRUE, input = NULL, show.output.on.console = TRUE,
       minimized = FALSE, invisible = TRUE, timeout = 0)

Arguments

Parameter Description
command the system command to be invoked, as a character string.
intern a logical (not NA) which indicates whether to capture the output of the command as an R character vector.
ignore.stdout, ignore.stderr a logical (not NA) indicating whether messages written to stdout or stderr should be ignored.
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 intern = TRUE. When running the command asynchronously, no output will be displayed on the Rgui console in Windows (it will be dropped, instead).
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.
timeout timeout in seconds, ignored if 0. This is a limit for the elapsed time running command in a separate process. Fractions of seconds are ignored.
show.output.on.console, minimized, invisible arguments that are accepted on Windows but ignored on this platform, with a warning.
show.output.on.console logical (not NA), indicates whether to capture the output of the command and show it on the R console (not used by Rterm, which shows the output in the terminal unless wait is false, and on some systems even when wait is false).
minimized logical (not NA), indicates whether a command window should be displayed initially as a minimized window.
invisible logical (not NA), indicates whether a command window should be visible on the screen.

Return Value

If intern = 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. Under the Rgui console intern = TRUE also captures stderr unless ignore.stderr = TRUE. If command runs but gives a non-zero exit status this will be reported with a warning and in the attribute "status" of the result: an attribute "errmsg" may also be available. If intern = FALSE, the r

Details

This interface has become rather complicated over the years: see system2 for a more portable and flexible interface which is recommended for new code. command is parsed as a command plus arguments separated by spaces. So if the path to the command (or a single argument such as a file path) contains spaces, it must be quoted e.g.by shQuote. Only double quotes are allowed on Windows: see the examples. (Note: a Windows path name cannot contain a double quote, so we do not need to worry about escaping embedded quotes.) command must be an executable (extensions .exe, .com) or a batch file (extensions .cmd and .bat): these extensions are tried in turn if none is supplied. This means that redirection, pipes, DOS internal commands, … cannot be used: see shell if you want to pass a shell command-li

Examples

Example
R
# NOT RUN {
# list all files in the current directory using the -F flag
# }
# NOT RUN {
system("ls -F")
# }
# NOT RUN {
# t1 is a character vector, each element giving a line of output from who
# (if the platform has who)
t1 <- try(system("who", intern = TRUE))

try(system("ls fizzlipuzzli", intern = TRUE, ignore.stderr = TRUE))
# zero-length result since file does not exist, and will give warning.
# }

See Also

shell or shell.exec for a less raw interface. man system and man sh for how this is implemented on the OS in use. .Platform for platform-specific variables. pipe to set up a pipe connection.