0

I have a funny requirement here, I have an already existing java program for which I have to write an automation in java. I have to show the merged output for both the programs as a report.

The output should be somewhat like this:

Output from program1 after executing line1
Output from myAutomation after executing line1

Output from program1 after executing line2
Output from myAutomation after executing line2


Output from program1 after executing line2
Output from myAutomation after executing line2

How can I achieve this in java? AFAIK, each java program runs separately in JVM and is isolated, so is this kind of stuff possible at all?

Rajesh Pantula
  • 10,061
  • 9
  • 43
  • 52
  • Your requirement is not clear, either go for multithreading in case of simultaneous operation or associate one program object into other and gets the combined result of both from _program-2_.. :) – Asif May 15 '12 at 11:11
  • I guess you can't start the existing java program from within your own automation, like `Program1 program1 = new Program1;program1.startToDoStuff();`? If not I would probably looks at something like described in this [thread](http://stackoverflow.com/questions/2460297/run-shell-command-from-java). I suspect it's not the cleanest solution though. :-) – Qben May 15 '12 at 11:13

2 Answers2

1

You make a very vague question, and without any code it might be a bit hard to answer your question.

My suggestion would be that you merge the two applications. You treat them as two individual objects, that both answers to one controller. If you can't, then I am a bit at a loss. Another option would be, that both programs write to the same file, and then you sort the outputs from the file.

OmniOwl
  • 5,477
  • 17
  • 67
  • 116
  • I second the "both programs write to the same file" approach: simple and effective (you just need to find out how to tell who's who in the resulting file) – Alex May 15 '12 at 11:09
  • but to write specific lines at specific times he probably needs to merge them into one program. At least if the lines are dynamic – keyser May 15 '12 at 11:10
  • Yeah he would have to time it. Else a third option would be, that he writes to two different files, and then sort them in a single application afterwards. – OmniOwl May 15 '12 at 11:11
0

A solution would be to use log4j and redirect the console output of the existing program to a file, and also configure the other program to output on the same file.

yiannis
  • 1,421
  • 12
  • 21