Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

bg_process

Start a background process


Description

Start a background process using the PowerShell cmdlet Start-Process -PassThru on Windows or the ampersand & on Unix, and return the process ID.

Usage

bg_process(
  command,
  args = character(),
  verbose = getOption("xfun.bg_process.verbose", FALSE)
)

Arguments

command, args

The system command and its arguments. They do not need to be quoted, since they will be quoted via shQuote() internally.

verbose

If FALSE, suppress the output from stdout (and also stderr on Windows). The default value of this argument can be set via a global option, e.g., options(xfun.bg_process.verbose = TRUE).

Value

The process ID as a character string.

Note

On Windows, if PowerShell is not available, try to use system2(wait = FALSE) to start the background process instead. The process ID will be identified from the output of the command tasklist. This method of looking for the process ID may not be reliable. If the search is not successful in 30 seconds, it will throw an error (timeout). If a longer time is needed, you may set options(xfun.bg_process.timeout) to a larger value, but it should be very rare that a process cannot be started in 30 seconds. When you reach the timeout, it is more likely that the command actually failed.

See Also

proc_kill() to kill a process.


xfun

Miscellaneous Functions to Support Packages Maintained by 'Yihui Xie'

v0.22
MIT + file LICENSE
Authors
Yihui Xie [aut, cre, cph] (<https://orcid.org/0000-0003-0645-5666>), Wush Wu [ctb], Daijiang Li [ctb], Xianying Tan [ctb], Salim Brüggemann [ctb] (<https://orcid.org/0000-0002-5329-5987>), Christophe Dervieux [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.