rsystem2

Add stdout = TRUE to R's system2 command and receive warning. Why?


I require the number of Firefox processes running on Linux (Ubuntu) be stored in a variable in an R script. By itself the system2 command I use seems to work. However, when I add stdout = TRUE to capture the info in a character vector I get a warning. Why the warning?

system2(command = "ps", args = "aux | grep [f]irefox -c")
# 0

system2(command = "ps", args = "aux | grep [f]irefox -c", stdout = TRUE)

Warning message:
In system2(command = "ps", args = "aux | grep [f]irefox -c", stdout = TRUE) :
  running command ''ps' aux | grep [f]irefox -c' had status 1

Solution

  • Use ef instead of aux as the argument to ps. aux for BSD and ef and variants for standard syntex, as per man ps.

    system2('ps', '-ef | grep [f]irefox -c', stdout = TRUE)
    [1] "12"