LoginSignup
0
0

More than 1 year has passed since last update.

標準出力と、クリップボードコピーを同時に行う

Last updated at Posted at 2021-05-29

なぜ?

標準出力とファイル出力を同時にする方法もあるが、いちいちファイル出力したくない...

コマンド

PS> $store=$null; <command> | Tee-Object -Variable store; $store | Set-Clipboard

<command> に実行したいコマンドを入力し、実行してください。
また、Powershellの場合、パイプで渡すと文字化けが発生しますので、上記コマンドを実行する前に以下コマンドを実行する必要があります。

$OutputEncoding = [Console]::OutputEncoding

処理の内容

  • クリップボードの中身を格納する変数($store)を用意します。
    • $store=$null;
  • 実行したいコマンドをパイプし、Tee-Object コマンドの -Variable オプションを使って、変数に実行結果を格納するようにします。
    • <command> | Tee-Object -Variable store;
  • 実行結果を格納した変数を Set-Clipboard コマンドを使って、クリップボードにコピーします。
    • $store | Set-Clipboard

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0