Redirecting errors to a text file

By: Borland Staff

Abstract: Some InterBase utilities (for example, gfix.exe) don't offer an output file switch to redirect status messages to a text file.

Problem:
How do I redirect errors from command-line programs that don't offer 
an output file switch?

Solution:
The information in this article applies to:

* InterBase 4.x
* InterBase 5.x

Some InterBase utilities (for example, gfix.exe) don't offer an output file 
switch to redirect status messages to a text file.  Following is an 
example of how the OS manages this within DOS and UNIX.

Legend:
     0 - Standard Input (stdin)
     1 - Standard Output (stdout)
     2 - Standard Error (stderr)

Upon opening a new shell, it sets up 0, 1 and 2 file handles.; the OS
determines the associated device for each handle.  Typically, 0 is the
keyboard, 1 is the display and 2 is a file.  Now a command-line analysis:

C:> gfix -l d:tmpemployee.gdb 2> d:tmperror.txt
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^
Step:                                  1              2         3

1) gfix -f -v d:tmpemployee.gdb
gfix runs and sets 0, 1 and 2 with the appropriate values:
     0 = "gfix -l d:tmpemployee.gdb"
     1 = ""
     2 = "database file appears corrupt ()
            -bad checksum
             -checksum error on database page 2"

 2) 2>
 The shell attaches to the associated device (a file in this case that
 holds the error information).

 3) d:tmperror.txt
 Takes the value from the associated device and redirects it to the text
 file.

This is not an InterBase-only feature.  Here is an example using 
normal OS utilities and the redirection feature:

C:> dir /r
Invalid switch - "r".

C:> dir /r 2> d:tmpdir.txt

C:> type d:tmpdir.txt
Invalid switch - "r".

Server Response from: ETNASC03