我正在創建一個 power shall 腳本來運行帶有引數的 exe 檔案。args 串列的構造方式是,如果 arg 的值為空或 null,則不應傳遞引數
下面是我的腳本
$runnerCommand = " "
[string]$splitRun = "20:1"
[string]$maxTestWorkers = "777"
[string]$retryTimes = "9"
[string]$testFilterInXmlFormat = "<filter><cat>XX</cat></filter>"
#$runnerCommand = '--testDllPath ' $testDllPath " "
if ($splitRun){
$runnerCommand = "--splitRun '$splitRun' "
}
if ($maxTestWorkers){
$runnerCommand = "--maxTestWorkers '$maxTestWorkers' "
}
if ($retryTimes){
$runnerCommand = "--retryTimes '$retryTimes' "
}
if ($testFilterInXmlFormat){
$runnerCommand = "--testFilterInXmlFormat '$testFilterInXmlFormat' "
}
$cmdPath = "C:\AutoTests\TestAutomation.Runner\bin\Debug\TestAutomation.Runner.exe"
& $cmdPath --testDllPath C:/AutoTests/Build/TestAutomation.TestsGUI.dll $runnerCommand
看起來 PowerShell 在最后一行代碼的 $runnerCommand 之前做了一個“新行”,導致沒有從 $runnerCommand 傳遞引數
請建議如何解決問題。
我嘗試了不同的方法
uj5u.com熱心網友回復:
您當前將所有引數作為單個字串傳遞。您應該使用一個陣列,每個引數作為一個單獨的元素。我實際上無法對此進行測驗,但是這樣的事情應該可以作業:
[string]$splitRun = "20:1"
[string]$maxTestWorkers = "777"
[string]$retryTimes = "9"
[string]$testFilterInXmlFormat = "<filter><cat>XX</cat></filter>"
$runnerArgs = @(
'--testDllPath', 'C:/AutoTests/Build/TestAutomation.TestsGUI.dll'
if ($splitRun) {
'--splitRun', $splitRun
}
if ($maxTestWorkers) {
'--maxTestWorkers', $maxTestWorkers
}
if ($retryTimes) {
'--retryTimes', $retryTimes
}
if ($testFilterInXmlFormat) {
'--testFilterInXmlFormat', $testFilterInXmlFormat
}
)
$cmdPath = "C:\AutoTests\TestAutomation.Runner\bin\Debug\TestAutomation.Runner.exe"
& $cmdPath $runnerArgs
請注意,PowerShell 允許if在陣列子運算式運算子 ( @()) 中使用運算式,包括 - 運算式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/531487.html
標籤:电源外壳
