4

While running a series of scripts through a command line interface, is there a way to add a header and footer while the body is scrolling verbose feedback of the currently running script?

The header would have information regarding the currently running script. The footer would have info to the user on controlling certain scripts and how to pause or stop the script.

Any ideas if anything likes this exists?

4

1 に答える 1

3

ウィンドウのタイトルを変更できます。これはヘッダーのように機能しますが、探しているものが正確に得られるかどうかはわかりません。

$Host.UI.RawUI.WindowTitle = "Your Custom Header"

Write-Progress コマンドレットを使用するというジャンボの提案は、純粋な PowerShell でフッターが表示される限り、おそらくほぼ同じくらい良いものです。

もう 1 つのオプションは、適切なヘッダー/フッターを提供する WinForms/WPF アプリで PowerShell ランタイムをホストすることです。非常に単純で不自然な例では、次のようなことを C# で行います。

// include the System.Management.Automation assembly & namespace
PowerShell ps = PowerShell.Create();
ps.AddCommand("Get-Process");
foreach (PSObject result in ps.Invoke()) {
  Console.WriteLine(result.Members["ProcessName"].Value);
}

コンソールに書き込む代わりに、おそらく出力を TextBox またはより適切なものにダンプします。

最後のオプションは、コンソールがCursorPositionプロパティを設定する機能を使用することです。スクロールする出力を上書きすることになるため、これは一種のハックですが、スクリプトの出力が制限されている場合は、次のように機能する可能性があります。

$pos = $Host.UI.RawUI.CursorPosition
$newPos = New-Object System.Management.Automation.Host.Coordinates 0,20
$Host.UI.RawUI.CursorPosition = $newPos
"Here is my footer on starting at the first character of line 20"
$Host.UI.RawUI.CursorPosition = $pos

プロパティを動的に調べて$Host.UI.RawUI.WindowSize.Height、フッターをウィンドウの下部近くに設定できます。出力が多い場合、デフォルトではテキストがスクロールすることを覚えておいてください。これには、画面を上にスクロールする古いバージョンのフッターも含まれます。

于 2012-05-03T19:36:08.303 に答える