关于PowerShell工作流程的UNC错误

时间:2017-10-04 11:20:10

标签: rscript powershell-workflow

当我运行以下powershell工作流程时:

Function Start-LocalRScript {
  Param([Parameter(ValueFromPipeline, Mandatory)]$Name)
  $ScriptPath = "C:\Exploration.RScripts"
  $RScriptExePath = "C:\Program Files\R\R-3.1.2\bin\Rscript.exe"
  $scriptPath = Join-Path -Path $ScriptPath -ChildPath $Name
  & $RScriptExePath $scriptPath
}

Workflow Get-RScriptWorkflow {
  Start-LocalRScript script1.R
}

我收到以下错误但仍然得到R脚本的结果:

Rscript.exe : '\\srvuser01\profil\myUser\Documents' At Get-RScriptWorkflow:2 char:2
+ CategoryInfo          : NotSpecified ('\\srvuser01\profil\myUser\Documents':String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName        : [localhost] 
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.  
[1] "from script 1"

但是当我运行命令Start-LocalRScript script1.R时,没有错误。似乎工作流正在尝试访问RScript.exe网络中用户的本地路径,即使我在脚本Start-LocalRScript上指定了RScript.exe的位置。有谁知道这里发生了什么?

1 个答案:

答案 0 :(得分:0)

而不是调用操作符(&)使用Start-Process并将-WorkingDirectory设置为正确的工作目录。