If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > How to redirect stderr and stdout to a file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-28-08, 05:44
sushantnirwan sushantnirwan is offline
Registered User
 
Join Date: Aug 2008
Posts: 2
Question How to redirect stderr and stdout to a file

Hi friends
I am facing one problem while redirecting the out of the stderr and stdout to a file
let example my problem with a simple example
I have a file (say test.sh)in which i run 2 command in the background

ps -ef &
ls &

and now i am run this file and redirect the output to a file (say output.log)
./test.sh > output.log

Now the result stored in the file is not like that first ps -ef and than ls
it mixed the output of both command

Now help me so thats i can store the result in the file only one after another

Thanks
Reply With Quote
  #2 (permalink)  
Old 09-01-08, 04:05
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
What do you expect? Both commands execute concurrently/in parallel and write their output concurrently to STDOUT. Thus, you will see the output of both commands intermixed. If you want to separate this, you should redirect the output of each command to a temp file and then read that temp file again.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 09-04-08, 06:18
yacovbm yacovbm is offline
Registered User
 
Join Date: Aug 2008
Posts: 3
Quote:
Originally Posted by sushantnirwan
Hi friends
I am facing one problem while redirecting the out of the stderr and stdout to a file
let example my problem with a simple example
I have a file (say test.sh)in which i run 2 command in the background

ps -ef &
ls &

and now i am run this file and redirect the output to a file (say output.log)
./test.sh > output.log

Now the result stored in the file is not like that first ps -ef and than ls
it mixed the output of both command

Now help me so thats i can store the result in the file only one after another

Thanks
remove the & from the commands to run one after the other

ps -ef
ls
Reply With Quote
  #4 (permalink)  
Old 09-04-08, 07:15
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Quote:
Originally Posted by yacovbm
remove the & from the commands to run one after the other

ps -ef
ls
This would not run the commands in background any longer.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On