Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Oct 2009 15:46:16 -0700
From:      George Davidovich <freebsd@optimis.net>
To:        freebsd-questions@freebsd.org
Subject:   Re: error output redirection
Message-ID:  <20091011224616.GA75228@marvin.optimis.net>
In-Reply-To: <f99a79ec0910111436g62b93acfg873771c04b6b9b1e@mail.gmail.com>
References:  <f99a79ec0910111436g62b93acfg873771c04b6b9b1e@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Oct 11, 2009 at 11:36:52PM +0200, Stefan Miklosovic wrote:
> if error output of some program appear on screen, it is possible to
> print it also to some file simultaneously?

Depends on the program, but generally, yes.

http://en.wikipedia.org/wiki/Standard_streams
http://en.wikipedia.org/wiki/Redirection_(computing)

> e.g if I "cat" file which do not exist, error is on screen, I want to
> add that error to some file (errors.txt)

Replacing 'cat file_that_does_not_exist' with 'badcommand'

  # redirect STDERR to a file
  badcommand 2> errors.txt

  # append STDERR to a file
  badcommand 2>> errors.txt

  # fun with file descriptors to have it both ways
  badcommand 3>&1 1>&2 2>&3 | tee errors.txt

-- 
George



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20091011224616.GA75228>