1

This is my code for run a java file in other java application but i dont knoow what to do if the program takes only bufferedinputs ??

try {

Runtime rt = Runtime.getRuntime();

// compile the java file
Process pr = rt.exec("javac Main.java");
pr.waitFor();

// run the java file
pr = rt.exec("java Main " + inputs.toString()); // using this i can give command line arguments 
pr.waitFor();
}

This is my code i can give command line arguments at run time but what if i want to give bufferedinput to the program ?

Thanks in advance

1 Answer 1

1

You state:

This is my code for run a java file in other java application but i dont knoow what to do if the program takes only bufferedinputs ??

To attach to another processes input and output streams, look at the API for the Process class where you'll find and use the getErrorStream(), getInputStream() and getOutputStream() methods. You can then wrap your Input and Output and Error Streams in their respective Buffered Streams.

Note however that you should be wary of common pitfalls which are well explained in the slightly dated article, When Runtime Exec Won't

Having said this, you're far better off using the Java classes themsevels rather than running it in another JVM. Is there a reason that you can't do this? And what do you mean by "buffered" input?

Sign up to request clarification or add additional context in comments.

2 Comments

He means System.in by buffered input
@NewOverHere: that still makes no sense whatsoever. How would another app know or have any idea if another app were using buffering to send input or not? All it knows is if it is getting input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.