Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2008
    Posts
    2

    Question Unanswered: 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

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

  3. #3
    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

  4. #4
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •