capture pid process via R when using system()

Viewed 61

in windows, would like to capture java pid using R system() like the following:

system("java -jar .\app.jar john_doe 1600_50_555", wait = FALSE)

have tried:

grep("^java.exe",readLines(textConnection(system('tasklist',intern=TRUE))),value=TRUE)

would like to capture that pid without using grep() or additional filtering.

1 Answers

You can use ps package for that.

library(ps)
library(dplyr)

system("java -jar .\app.jar john_doe 1600_50_555", wait = FALSE)

pid <- ps() %>% 
  filter(name == "java.exe") %>% 
  pull(pid)
Related