Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 24-02-2010
Member
 
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.
Reply With Quote
  #2  
Old 24-02-2010
Member
 
Join Date: Feb 2008
Posts: 1,848
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.
Reply With Quote
  #3  
Old 24-02-2010
Member
 
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 &
Reply With Quote
  #4  
Old 24-02-2010
Member
 
Join Date: May 2008
Posts: 2,293
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.
Reply With Quote
  #5  
Old 24-02-2010
Member
 
Join Date: May 2008
Posts: 2,383
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,
)
Reply With Quote
  #6  
Old 24-02-2010
Member
 
Join Date: May 2008
Posts: 2,008
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to redirect the output of two programs in the same file"
Thread Thread Starter Forum Replies Last Post
getting Error splicing file: Input/output error while copying file in ubuntu Rajni Operating Systems 10 09-01-2012 07:48 AM
Windows Batch file to output directory names and size to txt file m2thearkus Software Development 6 16-07-2010 12:04 AM
How to show output on both screen and file in c++? KAILEY Software Development 5 12-02-2010 05:22 PM
Terminal output to a file Naval Operating Systems 3 26-02-2009 09:00 PM


All times are GMT +5.5. The time now is 02:47 AM.