我正试图在cmd.exe中调用Powershell脚本,该脚本位于如下位置:c:\foo-bar\location-1\ShellScript.ps1
当我调用这个脚本时,我曾尝试在路径周围使用单引号和双引号,但没有成功。
PowerShell.exe -File "c:Datafoo - barlocation-1ShellScript.ps1" Arg1 Arg2
从我所读到的内容来看,我认为上面的内容会起作用,但这并不起作用,单引号也不起作用。
我很感激任何想法。
谢谢*编辑*在我的示例路径上键入错误。很抱歉
一个解决方案是转移到PowerShell v3,在那里可以很好地工作:
PS> powershell.exe -file 'C:tempfoo - barlocation-1foo.ps1' arg1 arg2
made it!, args are arg1, arg2
如果你需要留在V2上,请尝试逃离空间,例如:
PS> powershell.exe -file "C:tempfoo` -` barlocation-1foo.ps1" arg1 arg2
从cmd.exe,这应该可以工作:
C:> PowerShell.exe -Command "& {& 'c:Datafoo - barlocation-1ShellScript.ps1' Arg1 Arg2}"
PowerShell.exe -File "c:Datafoo - barlocation-1ShellScript.ps1"
应该逃脱
PowerShell.exe "& ""c:Datafoo - barlocation-1ShellScript.ps1"""
是的,实际上总共有6个双引号