【发布时间】:2016-11-01 10:01:27
【问题描述】:
已经有一些关于如何调用一个 PS 脚本与另一个类似的参数的问题 Powershell: how to invoke a second script with arguments from a script
但如果我的第一个脚本有多个位置参数,我会卡住。
testpar2.ps1 调用 testpars.ps1
#$arglist=(some call to database to return argument_string)
$arglist="first_argument second_argument third_argument"
$cmd=".\testpars.ps1"
& $cmd $arglist
$arglist 变量应使用数据库中的字符串填充。此字符串包含 testpar.ps1 的参数。
testpars.ps1 看起来像
echo argument1 is $args[0]
echo argument2 is $args[1]
echo arugment3 is $args[3]
# some_command_call $arg[0] $arg[1] $arg[2]
这个参数应该以某种方式在 testpars.ps1 中使用,比如将它们路径到某个命令。
但是当我运行 testpars2.ps1 我得到了
argument1 is first_argument second_argument third argument
argument2 is
arugment3 is
它认为这是一个论点,而不是它们的列表。
【问题讨论】:
-
echo arugment3 is $args[3]你是说$args[2]吗?
标签: powershell