我有一个批处理文件test.bat,用于启动powershell脚本:
@pushd "C:\myscripts"
powershell .\test.ps1 arg1 "arg2 with space" arg3
@popd
脚本test.ps1(位于C:\ myscripts)非常简单,如下所示:
# just print out the arguments
Write-Output ("args count: {0}" -f $args.length)
$args
接着我尝试启动test.bat。我应该传递三个参数到ps1文件,但是我得到了以下结果:
参数数量:5 arg1 arg2 with space arg3
在脚本中,我期望args[0]是arg1,args[1]是"arg2 with space",args[2]是arg3。我不明白为什么脚本实际上会得到5个参数。
我该如何将参数从cmd或批处理文件传递到powershell中,以达到我期望的效果?就像这样:
args count: 3
arg1
arg2 with space
arg3
cmd
,它们确实有不同的含义。 - Joey