Closed wlandau closed 1 year ago
R.exe
starts an Rterm.exe
subprocess AFAIR, that's the process that runs the R interpreter:
path <- file.path(R.home("bin"), "R.exe")
handle <- processx::process$new(
command = path,
args = c(
"--slave", "-e",
'ps::ps_descent()[1:5]'
),
stdout = "|"
)
handle$get_pid()
#> [1] 21424
handle$wait()
cat(handle$read_all_output())
#> [[1]]
#> <ps::ps_handle> PID=18324, NAME=Rterm.exe, AT=2023-04-19 12:12:11
#>
#> [[2]]
#> <ps::ps_handle> PID=5644, NAME=cmd.exe, AT=2023-04-19 12:12:11
#>
#> [[3]]
#> <ps::ps_handle> PID=21424, NAME=R.exe, AT=2023-04-19 12:12:11
#>
#> [[4]]
#> <ps::ps_handle> PID=6040, NAME=Rterm.exe, AT=2023-04-19 12:12:10
#>
#> [[5]]
#> <ps::ps_handle> PID=20468, NAME=Rterm.exe, AT=2023-04-19 12:05:26
#>
Created on 2023-04-19 by the reprex package (v2.0.1)
Ah, that makes sense. Thank you for explaining.
When I call R from
processx
on my Windows machine, I see different outputs when I compareget_pid()
from the handle toSys.getpid()
from within the process. Am I missing something?Created on 2023-04-19 with reprex v2.0.2
Session info
``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.2.3 (2023-03-15 ucrt) #> os Windows 10 x64 (build 19044) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.utf8 #> ctype English_United States.utf8 #> tz America/New_York #> date 2023-04-19 #> pandoc 2.18 @ C:/Program Files/RStudio/bin/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> cli 3.6.0 2023-01-09 [1] CRAN (R 4.2.2) #> digest 0.6.29 2021-12-01 [1] CRAN (R 4.2.1) #> evaluate 0.16 2022-08-09 [1] CRAN (R 4.2.1) #> fansi 1.0.3 2022-03-24 [1] CRAN (R 4.2.1) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.1) #> fs 1.5.2 2021-12-08 [1] CRAN (R 4.2.1) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.1) #> highr 0.9 2021-04-16 [1] CRAN (R 4.2.1) #> htmltools 0.5.3 2022-07-18 [1] CRAN (R 4.2.1) #> knitr 1.39 2022-04-26 [1] CRAN (R 4.2.1) #> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.2.2) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.1) #> pillar 1.8.1 2022-08-19 [1] CRAN (R 4.2.1) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.1) #> processx 3.8.0 2022-10-26 [1] CRAN (R 4.2.3) #> ps 1.7.1 2022-06-18 [1] CRAN (R 4.2.1) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.2.1) #> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.2.1) #> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.2.0) #> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.2.0) #> R.utils 2.12.0 2022-06-28 [1] CRAN (R 4.2.1) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.1) #> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.2.1) #> rlang 1.0.6 2022-09-24 [1] CRAN (R 4.2.2) #> rmarkdown 2.15 2022-08-16 [1] CRAN (R 4.2.1) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.2.1) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.1) #> stringi 1.7.8 2022-07-11 [1] CRAN (R 4.2.1) #> stringr 1.4.1 2022-08-20 [1] CRAN (R 4.2.1) #> styler 1.7.0 2022-03-13 [1] CRAN (R 4.2.1) #> tibble 3.1.8 2022-07-22 [1] CRAN (R 4.2.1) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.2.1) #> vctrs 0.5.2 2023-01-23 [1] CRAN (R 4.2.2) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.1) #> xfun 0.32 2022-08-10 [1] CRAN (R 4.2.1) #> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.2.1) #> #> [1] C:/Users/landau/AppData/Local/R/win-library/4.2 #> [2] C:/Program Files/R/R-4.2.3/library #> #> ────────────────────────────────────────────────────────────────────────────── ```