commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yi Huang <ethanhuang1...@gmail.com>
Subject [exec]How could I use exec to execute a java program with keyboard input in it?
Date Tue, 27 Sep 2011 07:41:03 GMT
For example:

import java.util.Scanner;

public class ToBeCalled {

public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int t = keyboard.nextInt();
System.out.println(t);
}
}

How could I use exec to let it run properly?
I have tried this:

// compile
cmdline = CommandLine.parse("javac");
executor = new DefaultExecutor();
cmdline.addArgument("ToBeCalled.java");
exitValue = executor.execute(cmdline);
System.out.println("compile: " + exitValue);

// run
cmdline = CommandLine.parse("java");
cmdline.addArgument("ToBeCalled");
cmdline.addArgument("abc");
cmdline.addArgument("def");
executor = new DefaultExecutor();
exitValue = executor.execute(cmdline);
System.out.println("run: " + exitValue);

It did compile, but crashed and said that there is no argument in nextInt()
How could I fix that?

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message