[英]Powershell: Command Passed To Start-Process Fails
首先,我分配此字符串变量:
PS> $newpath="C:\Program Files (x86)\Intel\iCLS Client"
这有效:
PS> [Environment]::SetEnvironmentVariable('Path', $newpath, 'Machine')
这不是:
PS> Start-Process Powershell -ArgumentList "-NoExit -noprofile -noninteractive -command [Environment]::SetEnvironmentVariable('Path', $newpath, 'Machine')" -Wait
第二个示例返回:
At line:1 char:46
+ [Environment]::SetEnvironmentVariable('Path', C:\Program Files (x86)\Intel\iCLS ...
+ ~
Missing expression after ','.
At line:1 char:47
+ [Environment]::SetEnvironmentVariable('Path', C:\Program Files (x86)\Intel\iCLS ...
+ ~~~~~~~~~~
Unexpected token 'C:\Program' in expression or statement.
At line:1 char:98
+ ... ient, 'Machine')
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingExpressionAfterToken
我究竟做错了什么? 我认为这与字符串,空格或引号有关。
谢谢
你是对的。 因为您的路径包含空格,所以必须将其引起来。 这应该工作:
Start-Process Powershell -ArgumentList "-NoExit -noprofile -noninteractive -command [Environment]::SetEnvironmentVariable('Path', '$newpath', 'Machine')" -Wait
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.