と間違っている何が私は2つのパラメータが期待するカウンタのスクリプトを持っています。PowerShellの私のカウントダウンタイマー
2)カウンタの持続時間(秒)。
例えば、私が3,を入力した場合、3秒後にタイマーが10から0にカウントダウンし、それを毎秒出力に書きます。
は、これは私のスクリプトです:
$timeBeforeStart = $args[0]
$waitSeconds = $args[1]
$startTime = get-date
$endTime = $startTime.addSeconds($waitSeconds)
$timeSpan = new-timespan $startTime $endTime
start-sleep -s $timeBeforeStart
while ($timeSpan -gt 0)
{
$timeSpan = new-timespan $(get-date) $endTime
write-host $([string]::Format("`rTime Remaining: {0:d2}:{1:d2}:{2:d2}",
$timeSpan.hours, $timeSpan.minutes, $timeSpan.seconds))
sleep 1
}
は、残念ながら、それは動作しません、スリープではなく、ディレイカウンタのカウンタとの同時性を動作するようです。
PS C:\> c:\555.ps1 3 10
Time Remaining: 00:00:07
Time Remaining: 00:00:05
Time Remaining: 00:00:04
Time Remaining: 00:00:03
Time Remaining: 00:00:02
Time Remaining: 00:00:01
Time Remaining: 00:00:00
Time Remaining: 00:00:00
私もと同じ結果-s スタート - 睡眠を試してみました。
ところで、睡眠と「睡眠開始」の違いは何ですか?