system2
invokes the OS command specified by command
.
system2(command, args = character(), stdout = "", stderr = "", stdin = "", input = NULL, env = character(), wait = TRUE, minimized = FALSE, invisible = TRUE)
command
.""
, 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.""
means the default,
alternatively a character string naming a file. Ignored
if input
is supplied.command
is redirected to the file.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
.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. 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 availableIn 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).
windows
Some Windows commands return out-of-range status values
(e.g. -1
) and so only the bottom 16 bits of the value are used.
system
, command
is always quoted by
shQuote
, so it must be a single command without arguments. For details of how command
is found see system
.
On Windows, env
is currently only supported for commands such
as R
and make
which accept environment variables on
their command line.
Some Unix commands (such as ls
) change their output depending
on whether they think it is redirected: stdout = TRUE
uses a
pipe whereas stdout = "some_file_name"
uses redirection.
Because of the way it is implemented, on a Unix-alike stderr =
TRUE
implies stdout = TRUE
: a warning is given if this is
not what was specified.
system
.
windows shell
and shell.exec
.