我试图在cmd.exe中调用Powershell脚本,脚本位于如下所示的位置:c:Data\foo - bar\_ location-1\ShellScript.ps1
当我调用此脚本时,我尝试在路径周围使用单引号和双引号,但没有运气.
PowerShell.exe -File "c:\Data\foo - bar\location-1\ShellScript.ps1" Arg1 Arg2
Run Code Online (Sandbox Code Playgroud)
根据我的阅读,我认为上述内容可行,但这不起作用,也没有单引号.
我很欣赏任何想法.
谢谢*编辑*我的示例路径上的Mistype.抱歉.
Kei*_*ill 10
一种解决方案是转到PowerShell v3,这可以正常工作:
PS> powershell.exe -file 'C:\temp\foo - bar\location-1\foo.ps1' arg1 arg2
made it!, args are arg1, arg2
Run Code Online (Sandbox Code Playgroud)
如果您需要继续使用V2,请尝试转义空格,例如:
PS> powershell.exe -file "C:\temp\foo` -` bar\location-1\foo.ps1" arg1 arg2
Run Code Online (Sandbox Code Playgroud)
从cmd.exe,这应该工作:
C:\> PowerShell.exe -Command "& {& 'c:\Data\foo - bar\location-1\ShellScript.ps1' Arg1 Arg2}"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12538 次 |
最近记录: |