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 5 years have passed since last update.

リダイレクト 標準出力と標準エラー出力は別々のチャネル

Posted at

スクリーンショット (414).png

cat > /etc/hosts
hostsの中身を表示

cat > /etc/hosts > output.txt
hostsの中身を output.txtファイルを作成して内容を記述
cat output.txt で内容が一致することを確認する

cat /hoge > output.txt
output.txt にエラーメッセージを書き込む(/hogeというディレクトリはないから)

結果は

スクリーンショット (415).png

エラーメッセージがoutput.txtに書き込まれずに表示されてしまった。

これは 「標準出力」と「標準エラー出力」が異なるチャネルを有しているからです。

標準エラー出力のリダイレクトを行いたい場合は 2> という記号を使う

スクリーンショット (416).png

ls /hoge 2> output.txt
こちらでは特に表示は出ない。

cat output.txt
output.txtの中身にエラーメッセージがリダイレクトされていることが分かる

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?