【发布时间】:2015-09-01 19:25:50
【问题描述】:
我正在尝试使用 PowerShell 调用位于包含空格的位置/路径的 EXE。当我从命令行调用脚本时,EXE 的完整路径没有传递给脚本。关于为什么会发生这种情况的任何想法?
PowerShell 脚本内容 (Untitled1.ps1)
这是从命令行调用的整个脚本:
param(
[string] $ParamExePath
)
function Run-CallThisExe {
param(
[string] $ThisExePath
)
Write-Host "ThisExePath: " "$ThisExePath"
start-process -FilePath $ThisExePath
}
write-host "ParamExePath: " $ParamExePath
Run-CallThisExe -ThisExePath "$ParamExePath"
命令行字符串
这是从 PowerShell 脚本的父文件夹运行的命令行字符串:
powershell -command .\Untitled1.ps1 -NonInteractive -ParamExePath "C:\path with spaces\myapp.exe"
输出
这是运行脚本后的输出
ParamExePath: C:\path
ThisExePath: C:\path
start-process : This command cannot be run due to the error: The system cannot
find the file specified.
At C:\sample\Untitled1.ps1:11 char:5
+ start-process -FilePath $ThisExePath
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
【问题讨论】: