R system functions always returns error 127

跟風遠走 提交于 2019-11-28 11:01:46
Tim Biegeleisen

As I mentioned in my comments, the R documentation reveals that in Windows the system() function does not launch a separate shell (if needed). This is why command line commands run with system(), but Notepad, which needs a separate window, does not run:

From the documentation for system():

The most important difference is that on a Unix-alike system launches a shell which then runs command. On Windows the command is run directly – use shell for an interface which runs command via a shell (by default the Windows shell cmd.exe, which has many differences from a POSIX shell).

Adapting @DavidTseng's answer (sorry for not having enough reputation to upvote it)...

system("cmd.exe", input = "notepad")

worked for me in Windows.

system("bash -l", input = "notepad")

for windows users wrong: system(path("c:", "program files", "r", "anysoft.EXE")) but works : system(path("c:", shQuote("program files"), "r", "anysoft.EXE"))

I'm not sure if there's been an update to R that allows this since the question was asked nearly four years ago, but system("\"C:\path\to\exe.exe\" args", intern = T) works for me and WILL bring up a separate child window and works on Windows 10 + R 3.6 + RStudio.

Not using the 'intern = T' was giving me a return code of 127 and did not run the process.

Bowen Chen

You guys are making it so complicated. I solved this problem by referring to this answer. The problem is with the PATH. type Sys.which('') in R, and you will see nothing. So you have to set the path in CMD, and then use Sys.setenv(PATH = '') in R to get this work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!