The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
search for a file - errors redirected matrixmadhan AIX 1 07-18-2005 01:12 AM
redirected output slavam Shell Programming and Scripting 2 10-12-2004 10:47 AM
tail -f a log file redirected into a new window? douknownam Shell Programming and Scripting 2 06-01-2004 01:34 PM
Standard output not redirected from /bin/sh soorajmu UNIX for Dummies Questions & Answers 1 09-19-2003 07:47 AM
Saving a redirected file JSP UNIX for Dummies Questions & Answers 1 09-27-2001 03:52 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 09-28-2007
Registered User
 

Join Date: Sep 2007
Posts: 26
redirected output not going to file for all cases

I have to confirm that an engine was not able to run. In the output below you see that it indeed got errors, but it didn't send those messages to the output file. When I run the same thing with a different executable it works. So does this mean something in the executable could cause it not to go to the output file??

$ cd Tar
$ ./Engine > ../engine_output.txt
exec(): 0509-036 Cannot load program ./Engine because of the following errors:
0509-150 Dependent module libodbc.a(libodbc.so.1) could not be loaded.
0509-022 Cannot load module libodbc.a(libodbc.so.1).
0509-026 System error: A file or directory in the path name does not exist.
$ cd ..
$ cat engine_output.txt
$ ls
AIX_50_ODBC_test.sh engine.tar engine_result.txt
Tar engine_output.txt
$
Reply With Quote
Forum Sponsor
  #2  
Old 09-28-2007
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,261
The errors are going to stderr (2) Normal output goes to stdout (1)

Code:
$ ./Engine 2>&1 > ../engine_output.txt
This makes both streams go to ../engine_output.txt
Reply With Quote
  #3  
Old 09-28-2007
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,587
Quote:
Originally Posted by jim mcnamara View Post
The errors are going to stderr (2) Normal output goes to stdout (1)

Code:
$ ./Engine 2>&1 > ../engine_output.txt
This makes both streams go to ../engine_output.txt
It won't make both streams go to the file becasue 2 is duplicated to 1 before 1 is redirected to the file. As a result stdout goes to the file and stderr goes to stdout.
Code:
$ ./Engine > ../engine_output.txt 2>&1
Reply With Quote
  #4  
Old 09-28-2007
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,261
You're correct, but as far as this code goes, both streams end up written to to log file.
Reply With Quote
  #5  
Old 09-28-2007
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,587
I disagree:

Code:
#!/bin/ksh
#
# test.sh : demonstrate redirection
#
#
echo "I am stdout"
echo "I am stderr" >&2
Code:
# ./test.sh > log1
I am stderr
# cat log1
I am stdout
Code:
# ./test.sh 2>&1 > log2
I am stderr
# cat log2
I am stdout
Code:
# ./test.sh > log3 2>&1
# cat log3
I am stdout
I am stderr
The order of redirection is important because if the duplication happens from 2 to 1 before redirection of 1, error output is redirected to fd1 ( stdout ) and standard output is redirected elsewhere. On the other hand if it happens afterwards the duplication is to "the same place as standard output"
Reply With Quote
  #6  
Old 10-02-2007
Registered User
 

Join Date: Sep 2007
Posts: 26
Thanks guys. This helps alot.
Reply With Quote
  #7  
Old 10-04-2007
Registered User
 

Join Date: Sep 2007
Posts: 26
This works for all my normal executions. But on one machine, a coredump is expected on one command. We don't care, just need to confirm the version info. This is output from the exe:

$ ./Up


-*-*- XXXXXXX UPDATE XXXXX Version nnnnnnnn -*-*-
-*-*- Copyright (C) 1998-2007 xxxxxxxxxxxxxx, Inc. -*-*-

Processing begins: 10/4/2007 10:48:12

Tracking Database Connect Error
Memory fault(coredump)

However, when I send the output to a file, the output file is empty:

$ ./Up > ../Up_output.txt 2>&1
Memory fault(coredump)
$ cd ..
$ cat Up_output.txt
$
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0