【问题标题】:Command works in powershell but not via system()/system2()/shell()?命令在 powershell 中工作,但不能通过 system()/system2()/shell() 工作?
【发布时间】:2021-03-05 15:19:38
【问题描述】:

我正在寻找从 R 运行 powershell 命令。它在 powershell 中运行,但我无法在 R 中运行。

这在 powershell 中有效

[guid]::NewGuid()

但这些都不适用于 R

system("[guid]::NewGuid()", intern=TRUE)
system2("[guid]::NewGuid()")
shell("[guid]::NewGuid()")

有什么想法吗?

【问题讨论】:

    标签: r powershell


    【解决方案1】:

    我认为您需要告诉system(),您想使用powershell 而不是cmd 作为可执行文件。

    假设 powershell 在你的 PATH 变量中尝试

    system('powershell -command "[guid]::NewGuid()"', intern=TRUE)
    

    您也可以尝试离开 intern=TRUE,具体取决于您期望的输出类型。

    【讨论】:

      猜你喜欢
      • 2023-03-28
      • 2018-01-13
      • 2011-05-11
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多