R系统函数总是返回错误127 [英] R system functions always returns error 127
问题描述
我需要从 R
执行外部工具,并在该工具中处理错误(如果有)。
我知道3个功能来做一些熟悉我的任务的事情:
I need to execute external tool from R
and process errors (if any) occurred in that tool.
I know 3 functions to do something familiar with my task:
shell, system and system2.
为了测试这些,我看到这个命令
Thying to test those, I see that command
shell("notepad")
打开记事本。据我所知,shell不允许检查错误(没有接口可以查看stderr)。
opens notepad. As far as I know shell doesn't allow to check errors (there's no interface to look into stderr).
当我调用
system("notepad")
或
system2("notepad")
R
冻结试图做出这些命令。
R
freezes trying to make those commands.
致电
system("start notepad")
或
system2("start notepad")
返回警告
Warning message:
running command '"start notepad"' had status 127
推荐答案
正如我在评论中提到的那样,R文档显示,在Windows中, system()
函数不会启动单独的shell(如果需要)。这就是为什么命令行命令以 system()
运行,但需要单独窗口的记事本不会运行:
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:
从文档对于 system()
:
最重要的区别是在Unix-同样的系统启动一个shell然后运行命令。在Windows上,该命令直接运行 - 使用shell通过shell运行命令(默认情况下,Windows shell cmd.exe与POSIX shell有很多不同)。
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).
这篇关于R系统函数总是返回错误127的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!