我想从R中打开文件。
我可以使用以下命令启动该软件(Graphpad Prism):
system2("C:/Program Files (x86)/GraphPad/Prism 7/prism.exe")
我希望这能打开我的棱镜文件,就像我双击它或从cmd运行它一样,但是没有:
system2("H:/Graphs/Shell/Templates/NASH4_Standard.pzfx")
我收到消息:
警告消息:运行命令“ H:/Graphs/Shell/Templates/NASH4_Standard.pzfx”的状态为127
我看到这不是错误,而只是警告。我是否在无意中将文档“脱壳”在后台?我如何确保它作为窗口弹出?
在Windows环境中,您需要调用命令行解释器,例如CMD提示符或PowerShell。另外,任何具有空格的文件路径都需要用双引号括起来,在R中需要用双引号括住字符串文字(对于您的.exe不是特定文件的情况)。
与system()
发送整个命令在一个字符串中:
system('cmd /c "H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"')
# POWER SHELL REQUIRES MORE QUOTE ESCAPING (ONLY ONE PAIR W/O SPACES)
system('powershell & """H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"""')
随着system2()
使用ARGS参数:
# FILES
system2('cmd', args=c('/c', '"H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"'))
system2('powershell', args=c(' & """H:/Graphs/Shell/Templates/NASH4_Standard.pzfx"""'))
# EXECUTABLES
system2('cmd', args=c('/c', '"C:/Program Files (x86)/GraphPad/Prism 7/prism.exe"'))
system2('powershell', args=c(' & """C:/Program Files (x86)/GraphPad/Prism 7/prism.exe"""'))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句