Skip to main content

Problem:

If you have an output file defined as

            SELECT myoutfile ASSIGN TO "OUTFILE"...

and when you run your program you need to print the output, you define it as follows:

  export dd_OUTFILE=">lp -s -dmyprinter"

or

  export dd_OUTFILE="|lp -s -dmyprinter

If instead you need the file on disk, you define it as follows:

  export dd_OUTFILE="mypath/myfile"

But what if you want to direct a file to another file AND print it at the same time?

Resolution:

If you need both, to get the output to a file and also to print it at the same time, what you need is to duplicate your output. So what you need is a command that is capable of duplicate what it gets from the standard input to the standard output and to a file. I think that the UNIX tee command is what you need.

This is an extract of man from HP-UX:

" NAME

      tee - pipe fitting

SYNOPSIS

      tee [-i] [-a] [file] ...

DESCRIPTION

      The tee command transcribes the standard input to the standard output

      and makes copies in the files.

    Options

           -i      This option ignores interrupts.

           -a      This option appends the output to the files rather than

                   overwriting the files.

"

So if you want to mix the following together:

Option a)

  export dd_OUTSAM="|lp -s -dmyprinter"

  ./myprogram

Option b)

  export dd_OUTSAM=myfile

  ./myprogram

You can do it, mixing a) and b) together using the tee command:

  export dd_OUTSAM="|tee myfile|lp -s -dmyprinter"

  ./myprogram

Old KB# 7291