Skip to contents

Invoke a command in the system command-line shell

Usage

shell(
  command,
  args = character(),
  print = interactive(),
  wd = getwd(),
  stderrFile = NULL,
  stdoutFile = NULL,
  stderrToStdout = FALSE,
  returnStdout = FALSE
)

Arguments

command

character(1). Name of program to run.

args

character. Arguments passed to command.

print

logical(1). Whether to print (echo) the commands to the console.

wd

character(1). Working directory path inside shell session.

stdoutFile, stderrFile

character(1) or NULL. File path to log stdout and/or stderr. Disabled when set NULL.

stderrToStdout

logical(1). Whether to redirect standard error (stderr) to standard output (stdout). Similar to 2>&1 in POSIX or &> in Bash.

returnStdout

logical(1). Whether to return stdout as a character vector, split by "\n".

Value

Invisible list. Contains named elements: "status", "stdout", "stderr", "timeout".

Note

Updated 2022-05-02.

See also

Examples

x <- shell(
    command = "printf",
    args = c("%s\n", "hello", "world"),
    print = TRUE
)
#> Running printf '%s
#> ' hello world
#> hello
#> world
print(x)
#> $status
#> [1] 0
#> 
#> $stdout
#> [1] "hello\nworld\n"
#> 
#> $stderr
#> [1] ""
#> 
#> $timeout
#> [1] FALSE
#>