0

Powershell スクリプトからユーザーにステータスまたは進行状況情報を表示するための規定の方法は何ですか? たとえば、「データベースに接続しています...」 通常、私は STDERR に出力します。

Powershell には Write-Progress コマンドレットがありますが、これはプログレス バー用です。

4

1 に答える 1

2

You can use the Write-Host cmdlet. The strings displayed via write host go directly to the console and are not considered part of the output stream. For example:

function foo {
    Write-Host "Entering foo"
    "Hello World"
    Get-Date
    [Math]::Pi
    Write-Host "Exiting foo"
}

PS> $results = foo
Entering foo
Exiting foo
PS> $OFS = ', '
PS> "Outputting results: $results"
Outputting results: Hello World, 11/05/2009 18:55:24, 3.14159265358979

Note that the output from Write-Host appears immediately on the host and does not not become part of the output stream (or in this case - output of function foo).

于 2009-11-06T01:52:00.557 に答える