process - make a simple java program that runs command prompt commands from the java program somewhat similar to jCreator -
i trying make simple java program runs command prompt commands java program similar jcreator.in here wanted compile , run relavant main class.
this code.but don't work properly.but out asking keyboard input program runs properly. please give me help.
my code is
import java.io.*; public class { private static void printlines(string name, inputstream ins) throws exception { string line = null; bufferedreader in = new bufferedreader( new inputstreamreader(ins)); while ((line = in.readline()) != null) { system.out.println(line); } } private static void runprocess(string command) throws exception { process pro = runtime.getruntime().exec(command); printlines(command + " stdout:", pro.getinputstream()); printlines(command + " stderr:", pro.geterrorstream()); pro.waitfor(); } public static void main(string[] args) { try { runprocess("javac main.java"); runprocess("java main"); } catch (exception e) { e.printstacktrace(); } } }
my main class
import java.util.*; public class main { public static void main(string[] args) { scanner input = new scanner(system.in); int x = input.nextint(); system.out.println(x); system.out.println("s"); system.out.println("ok"); } }
Comments
Post a Comment