我需要从,R
,执行一个外部工具,并处理该工具中发生的错误(如果有)。
我知道3个函数来完成我的任务:
shell, system and system2.
尝试测试那些,我看到那个命令
shell("notepad")
打开记事本。据我所知,shell不允许检查错误(没有接口(interface)可以查询
stderr
)。当我打电话
system("notepad")
要么
system2("notepad")
R
冻结尝试执行这些命令的过程。呼唤
system("start notepad")
要么
system2("start notepad")
返回警告
Warning message:
running command '"start notepad"' had status 127
最佳答案
正如我在评论中提到的那样,R文档揭示了在Windows中system()
函数不会启动单独的shell(如果需要)。这就是为什么命令行命令使用system()
运行,但是需要单独窗口的记事本无法运行的原因:
从documentation中获取system()
: