system2("powershell", args=c("-File", "C:\\PathToFile\\PowerShellScript.ps1"))
powershell脚本本身非常简单。它应该启动PowerPoint(出于演示目的)。
Start-Process "powerpnt.exe"
但是,执行失败的失败以下错误输出(我将其翻译成英语,因此希望内容正确给出...)
Error处理文件“ C:\ Pathtofile”,因为该文件 没有扩展名为“ .ps1”。输入Gwindows Powershell 版权(C)Microsoft Corporation。保留所有权利安装最新的powershell
一些注释:
我的PowerShell版本是5.1.22621.4391,您可以看到我的文件具有扩展名
.ps1
我还试图设置一个更好的拟合executionPolicy,但是在PowerShell中,另一个executionPolicy
unrestructiond with withpowershell -File C:\Path with spaces\to\file.ps1
解决此问题的方法是用字面的引号符合道路的全部范围:powershell -File "C:\Path with spaces\to\file.ps1"
在r字符串中,您应该能够用简单的逃生序列
表达
system2("powershell", args=c("-File", "\"C:\\PathToFile\\PowerShellScript.ps1\""))