Results 1 to 6 of 6

Thread: How to redirect the output of two programs in the same file

  1. #1
    Join Date
    Oct 2008
    Posts
    116

    How to redirect the output of two programs in the same file

    Hello friends

    I am trying to create do some coding in Linux where my two programs which communicate through message queues and right now both of them output is being redirected to two different files. But i am planning to have it in the same file. Can anyone help me out in this, i already asked my friends about it but they also don't know what would be the code.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Redirect the output of two programs in the same file

    Sure i will help you out with this but before that may i know which code are your using it or if you can give me more detail information about your code that would be very helpful for me.

  3. #3
    Join Date
    Oct 2008
    Posts
    116

    Re: How to redirect the output of two programs in the same file

    I am trying to use the below code for getting output to my files but the problem is that i cannot make temporary relationship between this two files where i can concatenate them in the order of writing that is the output should be the content of prog1 and then prog 2

    Code:
    prog1> & file1
    prog2> file2 &

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Redirect the output of two programs in the same file

    As per my knowledge it is impossible to output 2 process to write to a single file, if you try to then the two process will overwrite the data of each other and you will get some another result. But if you really want to display output of two files in one file then i think you can do it by using time indicator as a result, i am not sure whether it will work for you or not.

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    How to redirect the output of two programs in the same file

    In that case i would suggest you to use the below code and i am sure by using this code you will be able to redirect the output of two programs in the same file

    Code:
    int main (void)
    (
     FILE * mut = NULL;
     FILE * vt = NULL;
     char line [max_size] = "";
    
     mut1 = popen ( "PGM", "r");
     vt1 = fopen ( "trace1.txt", "a");
    
     while (fgets (line, max_size, mut)! = NULL)
     (
      fprintf (vt, "% s", line);
     )
    
     fclose (vt1);
     pclose (mut1);
     
     return 0,
    )

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    How to redirect the output of two programs in the same file

    If you really want something smooth then you need to use Faura fork(), the close () and dup () or you can also write a shell script where it will redirect stderr to stdout causing stdout to close and you will not face any issue with it, I am sorry i am not able to provide any example what i had mention.

Similar Threads

  1. Replies: 10
    Last Post: 09-01-2012, 07:48 AM
  2. Windows Batch file to output directory names and size to txt file
    By m2thearkus in forum Software Development
    Replies: 6
    Last Post: 16-07-2010, 12:04 AM
  3. How to show output on both screen and file in c++?
    By KAILEY in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 05:22 PM
  4. Terminal output to a file
    By Naval in forum Operating Systems
    Replies: 3
    Last Post: 26-02-2009, 09:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,814,951.55178 seconds with 16 queries