Pow*_*ool 12 error-handling shell r system system2
我需要执行外部工具R并处理该工具中发生的错误(如果有的话).我知道3个函数可以完成我的任务:
shell, system and system2.
Run Code Online (Sandbox Code Playgroud)
为了测试这些,我看到了那个命令
shell("notepad")
Run Code Online (Sandbox Code Playgroud)
打开记事本.据我所知,shell不允许检查错误(没有接口可以查看stderr).
我打电话的时候
system("notepad")
Run Code Online (Sandbox Code Playgroud)
要么
system2("notepad")
Run Code Online (Sandbox Code Playgroud)
stderr 冻结试图制作这些命令.
调用
system("start notepad")
Run Code Online (Sandbox Code Playgroud)
要么
system2("start notepad")
Run Code Online (Sandbox Code Playgroud)
返回警告
Warning message:
running command '"start notepad"' had status 127
Run Code Online (Sandbox Code Playgroud)
小智 14
改编@ DavidTseng的答案(抱歉没有足够的声誉来支持它)......
system("cmd.exe", input = "notepad")
Run Code Online (Sandbox Code Playgroud)
在Windows中为我工作.