【发布时间】:2019-08-17 19:18:10
【问题描述】:
我有一个运行以下命令的脚本:
$result = Start-Process -Wait -PassThru $proc $args
我想测量需要多长时间。基于this article,我正在尝试以下操作:
$buildtime = measure-command -expression { $result = Start-Process -Wait -PassThru $proc $args }
不幸的是,它抛出了以下错误:
Start-Process : Cannot validate argument on parameter 'ArgumentList'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null values and then try the command again. At C:\!scripts\pullandbuild.ps1:78 char:90 + ... d -expression { $result = Start-Process -Wait -PassThru $proc $args } + ~~~~~ + CategoryInfo : InvalidData: (:) [Start-Process], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartProcessCommand
由于我在字符串和变量扩展方面遇到的其他问题,$args 的定义如下:
$args = @"
& -quit -batchmode -logFile "$logfile" -buildWindows64Player "$($fullpath)\Project.exe"
"@
我该如何解决这个问题?还是有另一种方法来捕获脚本的运行时?我正在尝试学习 PS,所以我宁愿避免在运行之前和之后捕获时间并进行比较,但如果这是我唯一的选择,我会的。
【问题讨论】:
-
不要手动给
$args写信,这是automatic variable
标签: powershell parameter-passing