转义字符串中的空格 - 外部命令

时间:2017-12-06 11:57:02

标签: powershell escaping

我尝试使用PowerShell运行外部命令$parsePref = "--%" $imageName = "Windows 7 Image" & wdsutil.exe $parsePref "/Add-Image /Name:$($imageName) /FileName:WDSBoot.wim ..."

An invalid parameter (7) was specified for command /add-image

返回错误:$imageName

"Windows7Image"更改为$imageName有效(无空格..) - 但这是不可取的。

如何处理switch (columnLength) { case 1: sotPoint = Point.measurement(measurementName) .time(System.currentTimeMillis(),TimeUnit.MILLISECONDS) .tag("source", "SOT") .tag(attributes[0],rsObj.getString(attributes[0])) .addField("recordcount", 1) .build(); break; case 2: sotPoint = Point.measurement(measurementName) .time(System.currentTimeMillis(),TimeUnit.MILLISECONDS) .tag("source", "SOT") .tag(attributes[0],rsObj.getString(attributes[0])) .tag(attributes[1],rsObj.getString(attributes[1])) .addField("recordcount", 1) .build(); break; default: System.out.println("Invalid column length"); } 变量中的空格?

1 个答案:

答案 0 :(得分:1)

将参数括在引号中:

& wdsutil.exe $parsePref "/Add-Image /Name:""$($imageName)"" /FileName:WDSBoot.wim ..."
相关问题