beavis11111
beavis11111

Reputation: 574

capture pid process via R when using system()

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.

Upvotes: 2

Views: 169

Answers (1)

Renato Dinhani
Renato Dinhani

Reputation: 36676

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)

Upvotes: 2

Related Questions