Title: call c++ exe from java
Tags: java;applet;process
Question: I am trying to call c++ exe from java applet.For this purpose am using processbuilder.My code is as follows
ProcessBuilder pb = new ProcessBuilder(s);
Process process = pb.start();
final InputStream is = process.getInputStream();
OutputStream out = process.getOutputStream();
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));
pw.println(1);
pw.println(1 +"" +2);
new Thread(new Runnable() {
public void run() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (java.io.IOException e) {
}
}).start();
pw.close();
The c++ exe looks like this when started:
Find the shortest path from s to t.
Find the associating path from s to t within length l.
Find the associating path from s to t within (1+beta) times of the shortest distance from s to t.
Please input the command (1-4):
once u input the command ,for example 1 we get
Please input s and t, separated by space:
After this you enter two numbers and you will get a network.
Am able to get till Please input s and t, separated by space: .After that it does not display anything.
Thanks.


Here is another answer: pw.println(1 +"" +2);
This sends the string 12, not 1 2.  The "" is a zero-length string.
Comment for this answer: Thanks for your reply.then how do i send in two numbers seperated by space?
Thanks
Comment for this answer: thanks.I added a space but still not getting the final output.It does not take in the arguments 1 and 2.any idea why so?
Comment for this answer: Is the C++ program reading from stdin, or directly from the console?
Comment for this answer: By printing a space between the numbers: `pw.println(1 + " " + 2);` - note the space between the quotes.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 2.5', 'CreationDate': '2010:00:07/28/10', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java><applet><process>', 'Title': 'call c++ exe from java', 'ViewCount': 660, 'id': 3356682, 'user_AboutMe': None, 'user_AccountId': 639336.0, 'user_DisplayName': 'joji', 'user_Reputation': 1.0, 'user_Views': 1.0, 'user_id': 404938.0}}