file descriptor Q, redirecting stderr and stdout to stdout and file.

file descriptor Q, redirecting stderr and stdout to stdout and file.

Post by Mohammed Isha » Sat, 13 May 2000 04:00:00



Hi,

I have a Bourne shell script, and I am trying to send the stdout and
stderr to a file and stdout.

My script looks something like this....

commmand << EOF > syn2gcf.${TODAY}.log 2>&1
other_commands
EOF

This sends the stdout and stderr to the log file. I would like to see
the same on my screen too.

thanks inadvance.

ishaq

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

file descriptor Q, redirecting stderr and stdout to stdout and file.

Post by Barry Margoli » Sat, 13 May 2000 04:00:00




Quote:>commmand << EOF > syn2gcf.${TODAY}.log 2>&1
>other_commands
>EOF

>This sends the stdout and stderr to the log file. I would like to see
>the same on my screen too.

command 2>&1 | tee filename

--

Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

file descriptor Q, redirecting stderr and stdout to stdout and file.

Post by David Lod » Sun, 14 May 2000 04:00:00






>>commmand << EOF > syn2gcf.${TODAY}.log 2>&1
>>other_commands
>>EOF
>>This sends the stdout and stderr to the log file. I would like to see
>>the same on my screen too.
>command 2>&1 | tee filename

As a caveat; be careful using this!

If you required the result of 'command' this will be mangled by the
tee (as $? is the last command in the pipeline)

If you need the return code you'll have to fudge it. I normally use a
function to write all my logfiles out which handles this case.

Or you could do:

{
   command <<-EOF 2>&1
   blah
   EOF
   [[ ${?} != 0 ]] && print "command failed"

Quote:} >${OutputFile}

dave
 
 
 

file descriptor Q, redirecting stderr and stdout to stdout and file.

Post by Chris F.A. Johns » Sun, 14 May 2000 04:00:00


: Hi,

: I have a Bourne shell script, and I am trying to send the stdout and
: stderr to a file and stdout.

: My script looks something like this....

: commmand << EOF > syn2gcf.${TODAY}.log 2>&1
: other_commands
: EOF

: This sends the stdout and stderr to the log file. I would like to see
: the same on my screen too.

        ( command 2>&1 << EOF
          other_commands
          EOF
        ) | tee syn2gcf.${TODAY}.log

(I'm not sure whether that's quite what you want.)
--
        Chris F.A. Johnson

        -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
               Everything in moderation - including moderation  

 
 
 

1. Establishing new streams for file descriptors stdin, stdout, stderr

Greetings!

I'm trying to "daemonize" a server program which runs on a few different
Unix platforms according to Section 1.7 of the comp.unix.programmer FAQ,
but I'm tripping over a couple of details which I don't understand.

I've accomplished the first six steps. (up to closing file descriptors
0, 1, and 2 in order to release stdin, stdout, and stderr).

I'm not quite sure how to go about step 7:

  7. Establish new open descriptors for stdin, stdout and stderr. Even if
  you don't plan to use them, it is still a good idea to have them open.
  The precise handling of these is a matter of taste; if you have a
  logfile, for example, you might wish to open it as stdout or stderr,
  and open `/dev/null' as stdin; alternatively, you could open
  `/dev/console' as stderr and/or stdout, and `/dev/null' as stdin, or
  any other combination that makes sense for your particular daemon.

I want to redirect stdout and stderr to append  file which I know exists, and
redirect stdin to /dev/null

I'm ignorant of how to force this association. I know that I could use open()
to open the file, but then I would just get whatever file descriptor the
system decided to give me. Does open() always use the file descriptors
in ascending order? Such that if I close these three, then do three opens,
I will get first 0, then 1, then 2? If not, is there a semi-portable way to
force an open with a particular file descriptor?

Am I far off here?

Thanks in advance!

Jeremy Beal
Get my e-mail address at www.nvmedia.com/jbeal
(Tired of the damn spam)

2. HELP NEEDED - memcpy(...)

3. UNIX file descriptor for stdin, stdout and stderr

4. Slackware: XDMCP and Getty problems

5. HELP: How to redirect stdout and stderr to a text file.

6. solaris 2.5.1 pkgadd question

7. bash : how to redirect both stdout and stderr to append a file

8. printing problems

9. Redirect stdout * stderr to one file in bourne sh using exec

10. redirect stdout and stderr to file (append) - basic stuff?

11. Redirect stderr and stdout in two separate files?

12. Problem with redirecting stdout and stderr to log file

13. Redirecting stderr & stdout to file and screen