Josh Close writes:
> How would I start up a program and redirect all output, stdin, stdout
> and stderr, to a file?

You wouldn't normally redirect stdin to a file, as stdin is standard input
and is almost always used for reading.

> program >> program_output.log

A single > truncates the file.  A double > (i.e. >>) appends to the file.

> .... can someone explain what the 2>&1 stuff means, or give me a link
> somewhere. That would probably solve my problems also. I don't really
> understand the redirection that well, or which 2/1/0 are.

The numbers are file descriptor (fd) numbers.  0 is stdin, 1 is stdout
(standard output) and 2 is stderr (standard error).  If you use the C
standard library, then the stdin, stdout and stderr variables correspond to
those file descriptors (see stdin(3) or stdio(3)).  A file descriptor is
used with the lower level functions, such as read(2), write(2), fstat(2),
etc., or can be used with fdopen(3).

(The above notation references man pages in a given section.  stdio(3) means
the stdio man page in section 3, accessed by running "man 3 stdio".  See
"man man" for more details.)

The syntax 2>&1 means to redirect fd 2 to fd 1.  More specifically, it
creates a copy of fd 1 onto fd 2, likely using dup2(2).  The order is
important.  See REDIRECTION in the bash man page for a more complete
explanation.

File descriptors are something that won't make a lot of sense until you
understand C programming and the POSIX API.

-- 
David Phillips <david at acz.org>
http://david.acz.org/


_______________________________________________
TCLUG Mailing List - Minneapolis/St. Paul, Minnesota
Help beta test TCLUG's potential new home: http://plone.mn-linux.org
Got pictures for TCLUG? Beta test http://plone.mn-linux.org/gallery
tclug-list at mn-linux.org
https://mailman.real-time.com/mailman/listinfo/tclug-list