How to run a java program through a different java program?

I want to run “” through “”. This is the the code I tried:

Runtime.getRunTime().exec("C:\\"+path+"\\java Test < In.txt > Out.txt");

But it did not worked.

Is there any other solution?

@aalhadkulkarni: If this is what u are looking for. :slight_smile: :slight_smile:


Use this to Compile–>

Runtime rt = Runtime.getRuntime();

Process p = rt.exec(“javac -d .”);

//It will create the class file on the current working location, means it will create Test.class file where your file is located.

And to Run–>

Runtime rt1 = Runtime.getRuntime();

Process p1 = rt1.exec(“java Test<<in.txt>>out.txt”);

//Remember you never use .java extension while executing the class file all you need is just the name of the class nothing more than that.

1 Like

I’d seen that code. But could not understand how to give input to the 2nd program (

HAPPY NEW YEAR to you too

i’ll search for a better explanation then :slight_smile:

thanks very much:)

Yes, it was a typing mistake (.java)

It is creating Test.class file. But not executing the program