Embedded nul warnings when invoking system2 with stdout = TRUE on Windows

146 Views Asked by At

When trying to retrieve current process command line info using wmic via the system2 interface:

system2(
  command = "wmic",
  args = paste0("process where processid=", Sys.getpid(), " get commandline"),
  stdout = TRUE
)

I get the following output and warnings:

[1] "ÿþC" ""    ""    ""    ""   
Warning messages:
1: In readLines(rf) : line 1 appears to contain an embedded nul
2: In readLines(rf) : line 2 appears to contain an embedded nul
3: In readLines(rf) : line 3 appears to contain an embedded nul
4: In readLines(rf) : line 4 appears to contain an embedded nul
5: In readLines(rf) : line 5 appears to contain an embedded nul
6: In readLines(rf) :
  incomplete final line found on '...\Temp\RtmpaWqnBy\file1284c476b1'

Interestingly, when using system, to get the same desired output (command line info on the current process) it seems to work fine:

system(
  command = paste0("wmic process where processid=", Sys.getpid(), " get commandline"),
  intern = TRUE
)

Output:

[1] "CommandLine                                                     \r"         "\"C:\\Program Files\\R\\R-3.6.2\\bin\\x64\\Rgui.exe\" --cd-to-userdocs  \r"
[3] "\r"  

Also, system2 with stdout = "" prints the output to console fine:

system2(
  command = "wmic",
  args = paste0("process where processid=", Sys.getpid(), " get commandline"),
  stdout = ""
)
CommandLine                                                     

"C:\Program Files\R\R-3.6.2\bin\x64\Rgui.exe" --cd-to-userdocs

I tried specifying the args argument to system2 in different ways, but with no luck. Could someone provide an explanation of the warnings? Some sessionInfo below:

  • R version 3.6.2 (2019-12-12), Running under: Windows 10 x64
  • Platform: x86_64-w64-mingw32/x64 (64-bit)
  • locale: LC_COLLATE=English_United Kingdom.1252

Some details on reproducing:

  • In an active R session, this issue only manifests for me within RGui, not e.g. in RStudio or an R session ran from command prompt (cmd.exe)
  • When the code is executed on startup (e.g. via .Rprofile), it manifests in both RGui and RStudio, but not in an R processes created from command prompt (cmd.exe)
0

There are 0 best solutions below