Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to redirect the console output from the batch file execution??

807589Aug 18 2008 — edited Aug 21 2008
* How to redirect the console output from the batch file execution...

* Redirect the output to a String object or Inputstream object....

* The following is my code,
import java.io.File;
import java.io.PrintStream;


public class ReadConsoleOut {

	public static void main(String[] args) throws Exception{
		File myfile = null;
		PrintStream print = null;
		Process proc = null;
		String file_path = null;

		file_path = new String("E:\\test\\runjar.bat");
		
		myfile = new File(file_path);
		print = new PrintStream(myfile);
		print.write("java -jar  run.jar -file \"E:/test/inputfile.xml\" ".getBytes());
		proc = Runtime.getRuntime().exec("cmd /c start  " + file_path);
	}
}
* In the above code jar file will be executed in an separate command prompt , i want to redirect that console output to
String object

* How it is possible?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 18 2008
Added on Aug 18 2008
33 comments
12,912 views