4

尝试wmic通过system2接口检索当前进程命令行信息时:

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

我得到以下输出和警告:

[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'

有趣的是,当使用system, 来获得相同的所需输出(当前进程的命令行信息)时,它似乎工作正常:

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

输出:

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

此外,system2stdout = ""输出打印到控制台:

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

我尝试以不同的方式指定args参数,但没有运气。system2有人可以解释警告吗?下面的一些sessionInfo

  • R 版本 3.6.2 (2019-12-12),运行于:Windows 10 x64
  • 平台:x86_64-w64-mingw32/x64(64位)
  • 语言环境:LC_COLLATE=English_United Kingdom.1252

关于复制的一些细节:

  • 在活动的 R 会话中,此问题仅在 RGui 中为我显现,而不是在 RStudio 中或从命令提示符 (cmd.exe) 运行的 R 会话中
  • 当代码在启动时执行时(例如通过 .Rprofile),它会同时出现在 RGui 和 RStudio 中,但不会出现在从命令提示符 (cmd.exe) 创建的 R 进程中
4

0 回答 0