system
Invoke a System Command

### Description

Launches an OS-specific (UNIX or Windows) command.

### Usage

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

### Arguments

command | a character string giving the command to invoke.
intern | a logical value. If TRUE, the output of command is captured as a character vector. If FALSE (the default), the command is directly executed.
ignore.stdout, ignore.stderr | a logical value. If TRUE, ignores the message written to stdout or stderr. The default is FALSE.
wait | a logical value. If TRUE (the default), the command is run in synchronous mode and system is not returned until command completes. If FALSE, the command is run in asynchronous mode. This option is useful when you want to use the engine and the application (command invoked) concurrently. If intern is TRUE, this argument is ignored and command is always run in "wait" mode.
input | a character vector. If specified, each character string is written to one line of a temporary file and this file is redirected as standard input of command.
show.output.on.console | a logical value. If TRUE (the default), the output is displayed in the console.
minimized | a logical value. If TRUE, runs the command in minimized windows. The default is FALSE.

invisible | a logical value. if TRUE (the default), runs the command in invisible mode.

### Details

system runs the specified command in UNIX or Windows.

- On the UNIX platform, only the first two arguments are passed and system uses the UNIX Shell to run the command.
- On the Windows platform, the command is directly executed.

As a result, the process, behavior, and error handling of the command on UNIX and Windows are quite different.
One difference is that the system function on Windows does not handle input and output indirection (in Spotfire Enterprise Runtime for R and in open-source R), whereas system on other platforms supports input and output indirection. If this is needed, a workaround is to call the cmd Windows command, which interprets indirection. Thus, system("findstr A < in.txt > out.txt") will not work, but system("cmd /C findstr A < in.txt > out.txt") will work. Alternatively, one could call the shell function.
Value
returns one of the following:

- If intern is TRUE, a character vector giving the output of the command.
- If intern is FALSE, a return code (invisible) by the command.

  - 0 indicates that the command has run successfully.
  - 127 indicates that the command failed to run.

See Also
shell.
Examples

    ## Not run:
    # Windows examples:
    system("cmd")
    system("cmd", intern  = TRUE)
    ret <- system("cmd", ignore.stdout   = TRUE)
    ret
    ## 0
    ret <- system("mycmd")
    ## Warning message:
    ## running command 'mycmd' had status 127
    ret
    ## [1] 127
    # Run notepad in "wait" mode.
    system("Notepad abc.txt", invisible = FALSE)
    # Run notepad concurrently
    system("Notepad", wait = FALSE, invisible = FALSE)
    # Run notepad in minimized window.
    system("Notepad", minimized = TRUE, invisible = FALSE)
    # Unix examples:
    system("ls", intern = TRUE)
    system("ls")

    ## End(Not run)

Package base version 6.1.5-18
Package Index