簡體   English   中英

system2(“bash”, “ls”) -> 無法執行二進制文件

[英]system2(“bash”, “ls”) -> cannot execute binary file

任何人都知道為什么

system2("bash", "ls") 

將導致(在 R-Gui 和 RStudio 控制台中)

/usr/bin/ls: /usr/bin/ls: cannot execute binary file 

而其他 shell 工作沒有問題(見下面的例子)和 RStudio 終端中的“bash”也工作沒有問題。 如果有補救措施?

工作system2示例:

system2("powershell", "dir") 

在這里在 Windows 10 上運行 R-3.6.3 ... 將“Git bash”作為“bash”執行。

PS:以防萬一有人想知道 - 我也嘗試了完整路徑,即/usr/bin/ls -> 相同的結果

好的 - 這可以解決問題

system2("bash", input = "ls")

因此,而不是args =...powershell命令一樣,需要(或更有趣的是,有時“可以”)將input =...參數與bash

或者正如@oguzismail 評論中提到的那樣,這也可以

system2("bash", "-c ls") 

以及@Christoph 指出的

system2("ls") 

有時也可以工作(即在某些 RStudio[?] 設置中它不會返回結果,在某些情況下它會返回)。

但是我注意到,R 版本與不同 RStudio 版本 [或更可能是語言環境] 的不同組合當然不會總是表現一致,這也取決於 bash 命令的可用性,例如ls (更一般地 /usr/bin) PATH 與否。

所以選擇最適合你的!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM