【发布时间】:2015-04-14 15:17:00
【问题描述】:
我正在尝试编写一个将使用 Installcfg.cfg 文件安装 Java 的 powershell 脚本。无论脚本在哪里执行,我都希望它能够运行。当任何文件路径中没有空格时,它工作正常,但是当我从另一个位置运行它时,我收到以下错误:
以下开关有错误: "INSTALLCFG='C:\Program";"Files";"(x86\DesktopCentral_Agent\swrepository\1\swuploades\Java";"8";"Update";"25\InstallCFG.cfg'";.
Powershell 似乎没有按照我的意愿传递文件路径。
脚本如下:
#Determine the Architecture
$Arch = (Get-WmiObject Win32_OperatingSystem).OSArchitecture
#Make sure no browsers are running
kill -processname iexplore, chrome, firefox
#Install based on Architecture
if ($Arch -eq "64-bit")
{
Start-Process jre-8u25-windows-x64.exe -wait -args "INSTALLCFG=$PSScriptRoot\InstallCFG.cfg /L c:\temp\java64.txt"
Start-Process jre-8u25-windows-i586.exe -wait -args "INSTALLCFG=$PSScriptRoot\InstallCFG.cfg /L c:\temp\java32.txt"
}
else
{
Start-Process jre-8u25-windows-i586.exe -args "INSTALLCFG=$PSScriptRoot\InstallCFG.cfg /L c:\temp\java32.txt"
}
我尝试了各种方法来在参数中包含引号,甚至将参数创建为变量。我不想对位置进行硬编码,因为我希望文件可以从任何地方运行。
我基本上是在尝试从 powershell 中的批处理文件中运行以下命令:
"%~dp0jre-8u25-windows-x64.exe" INSTALLCFG="%~dp0InstallCFG.cfg" /L c:\temp\log.txt
我错过了什么?
【问题讨论】:
标签: java powershell path spaces