redirected output not going to file for all cases


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers redirected output not going to file for all cases
# 1  
Old 09-28-2007
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
$
# 2  
Old 09-28-2007
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
# 3  
Old 09-28-2007
Quote:
Originally Posted by jim mcnamara
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

# 4  
Old 09-28-2007
You're correct, but as far as this code goes, both streams end up written to to log file.
# 5  
Old 09-28-2007
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"
# 6  
Old 10-02-2007
Thanks guys. This helps alot.
# 7  
Old 10-04-2007
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
$
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting redirected pwd from file.

Hi echo " username " read username echo "password" stty -echo read password stty echo through read i am taking standard input and redirecign them to a file echo " username=${username}/${password} " > file.lst now from the same shell script i want to delete the password (i.e... (4 Replies)
Discussion started by: rosheks
4 Replies

2. UNIX for Dummies Questions & Answers

Dot and redirected output syntax in a tar command

Hi All, Please could anyone advise what the purpose of the dot syntax in the following command means: tar -cvf ${WORKING_BACKUP_ROOT}/${TAR_ARCHIVE_FILE} . >/${BACKUP_ROOT}/${ARCHIVE_LOG} Many thanks (2 Replies)
Discussion started by: daveu7
2 Replies

3. UNIX and Linux Applications

missing delimiters when mysql output is redirected to log file

Hi, Pls check that '|' and '+' present in Step-1 are not copied to log file in Step-3. Pls suggest how to get the exact output from Step-1 (i.e. with out losing '|' and '+') in to a log file ~Thanks Step-1: Execute command > mysql -utest -ptest -htesthost testdb -e "select * from... (3 Replies)
Discussion started by: newbielgn
3 Replies

4. Shell Programming and Scripting

Redirecting output that was redirected to variable and console

Hi all, I would like to store the output of a command in a variable and output it to the console at the same time. This is working fine using the following construct var=`command | tee /dev/tty` I use this in some scripts to display the output of the command on the console and, at the same... (2 Replies)
Discussion started by: script_man
2 Replies

5. Shell Programming and Scripting

Exclude Certain Entries from Piped or Redirected Output?

I want to execute a command something like: find / -name "jni.h" and I want to direct the output of that command to some type of filter that will leave out all the lines reporting inaccessible directories (permission unavailable). Is this a pipe or a redirect? For example, output like... (1 Reply)
Discussion started by: downplay
1 Replies

6. Shell Programming and Scripting

no data redirected to a file with top and grep - why?

HI all, I want to capture cpu data in batch mode of "top" command and redirect to a file like this: top -b > cpu.dat it works! But I want to capture only Cpu lines, so i have: top -b | grep ^Cpu >cpu.dat Then I got an empty output file. Why? Could somebody explain and help me to make it... (15 Replies)
Discussion started by: fongthai
15 Replies

7. AIX

search for a file - errors redirected

hi all, i do search for a file in solaris box in the following format find / -name 'file' -print 2>/dev/null i tried the same thing on AIX box; as i am searching from the root the same way i redirected the errors to /dev/null but find is showing strip off errors and when i just continued... (1 Reply)
Discussion started by: matrixmadhan
1 Replies

8. Shell Programming and Scripting

redirected output

Hello Everyone, I have an option for users in my shell script to create log file. So if user saying “yes” on it, I'm redirecting all output to log file by doing this: > /output.log. However I would like the output being displayed on the screen at the same time. Is it possible? If yes, does anybody... (2 Replies)
Discussion started by: slavam
2 Replies

9. UNIX for Dummies Questions & Answers

Standard output not redirected from /bin/sh

I have an application which has a lot of cout & cerr statements. This application also opens a log file (for eg a.log). When this application is run from the inittab file as follows /bin/sh -c " . /etc/timezone; exec /test" all the cout & cerr statements are printed in the log file... (1 Reply)
Discussion started by: soorajmu
1 Replies

10. UNIX for Dummies Questions & Answers

Saving a redirected file

What command do I use in order to save a file in directory A/B/C to directory A/D/E. (1 Reply)
Discussion started by: JSP
1 Replies
Login or Register to Ask a Question