Help us understand the problem. What is going on with this article?

エラー出力を標準出力にまとめる

More than 1 year has passed since last update.
  • 2>&1を使うとエラー出力を標準出力にまとめる事ができます
$ sh -c "date" > ./log # dateの標準出力がshの標準出力としてlogに書き出される
$ cat log
2018年  9月  7日 金曜日 16:36:08 JST

$ sh -c "dat" > ./log # dat(dateのtypo)を実行するとエラーが出る、エラーはshの標準出力に含まれないため logには空文字が書き込まれる
$ cat log # 当然何も出力されない

$ sh -c "date 2>&1" > ./log # dateのエラーも標準出力にまとめる、logにはdateの出力全てが書き出される
$ cat log
2018年  9月  7日 金曜日 16:41:38 JST

$ sh -c "dat 2>&1" > ./log # datのエラーも標準出力にまとめる、logにはdatの出力全てが書き出される
$ cat log
sh: 1: dat: not found # これはlogの中身
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした