How to interact with app started from ant?
In the process of building a P2P app for a class, I start a number of peers from an ant build file before starting one in "interactive" mode.
The ant docs on the task states that one can interact with a forked app since ant-1.6.3
The code to read input is:
while (true) {
System.out.println("> ");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
String cmd = "";
try {
cmd = br.readLine();
System.out.println(cmd + "hier");
if (cmd == null)
continue;
if (cmd.equals("hello")) {
System.out.println("Port: ");
int bsPort = new Integer(br.readLine());
System.out.println("IP (blank for localhost): ");
String bsIp = br.readLine();
if (bsIp.equals(""))
bsIp = "127.0.0.1";
bootstrap(bsIp, bsPort);
}
else if (cmd.equals("plist")) {
plist();
}
else i开发者_开发百科f (cmd.equals("nlist")) {
nlist();
}
else {
System.out.println("Command was read as: " + cmd);
}
} catch (IOException ioe) {
System.out.println("IO error trying to read your command!");
System.exit(1);
}
The relevant ant task is:
The ant task can apparently not be shown by SO, but it's basically a java fork="false" block.
Of note is that I run the root and subsequent peers in parallel -> daemons blocks to get them to run in the background. Those are forked.
I have tried with fork="true" and fork="false" (finding a link that said to set it to false) - both to no avail.
I have found one link saying that I can use a TimedBufferedReader, but am a bit wary to do so only to please ant...
Seems the daemon tasks hijacked System.in. Setting an inputstring="" argument on those did the prevented them from doing so, and let me interact with the interactive client.
Just to let others know, if one outputs via System.out.print instead of System.out.println, one will not see the output before after having given the input...
精彩评论