Hi I have a command line java program I can call and it prints information out. ( I can run it with : java program infile1 infile2) I'd like to create another program that can call this first program. How could this be done?
Well, you could take the program that you have now. Take the stuff that you have in the main() method and put it in a constructor that takes the infiles as parameters. Write your second class and have it create an object of the the first class using those two parameters. But something tells me that there are some design issues that you have not considered. Actually, the question sounds sort of "procedural". Want to explain more of what you are trying to accomplish?
"JavaRanch, where the deer and the Certified play" - David O'Meara
Joined: Dec 12, 2000
These classes were given to me, so I'd prefer to use them as is and just do up a gui to visualize the results. I prefer not to change code that works. I tried the making a new method. That worked. I also tried. Program program = new Program(); program.main( args ); and this worked. Is this a bad thing.
hi zoe, all the suggestions till now r valid but what if you can't combine two codes??? say u have two different programs in a obfuscated form. then what u'll do?? i would prefer using Runtime.exec(String) method that creates another Process in the program and we can get results by getting InputStream from the Process object and do the stuff...we can even pipe the input to the program using OutputStream of the Process object. See, java.lang.Runtime, java.lang.Process classes... regards, maulin