0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

コマンドプロンプトの2>&1はパイプ途中にも使える

Last updated at Posted at 2022-06-01

2>&1、ファイルリダイレクトと違ってパイプ途中にも使えるっぽい
できないかと思ってました
(ファイルリダイレクトだと確かできない、ファイルへのリダイレクトと出力のリダイレクトだと別物ってことなのだろうか)
軽く調べてみた感じunixな環境でもそういう感じの挙動をするっぽい
clip使おうかとも思ったけどエラー自体は表示されちゃうのが癪だし、エラーを握りつぶしてそのままheadしてコンソールに表示したかったので助かった(そもそもそういうことをしないで済むようにしろという話ではある)

例:

C:\CLI>fc
FC: ファイル指定の数が不足しています  # エラー出力に出力されている


C:\CLI>fc | clip
FC: ファイル指定の数が不足しています  # クリップボードへ転送できておらず、エラー出力にそのまま出ている


C:\CLI>fc 2>&1 | clip
# クリップボードに上記のエラー出力の内容が入った

あと、2>&1に限らず2>nulみたいな記述も普通に使える

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?