This site requires JavaScript, please enable it in your browser!
Greenfoot back
plsurveyor
plsurveyor wrote ...

2013/9/15

How to fire a command line from greenfoot

plsurveyor plsurveyor

2013/9/15

#
I am writing a Java learning tool in Greenfoot. It's already working and I have this code.
public static void runProc(String cmd) throws Exception{
    Process proc = Runtime.getRuntime().exec(cmd); //executes terminal command received
    debug(cmd + ">", proc.getInputStream());
    debug(cmd + "[ERROR]", proc.getErrorStream());
    proc.waitFor();
    //System.out.println(cmd + " exitValue(): " + proc.exitValue());
}

public static void debug(String name, InputStream ins) throws Exception{
    String line = null;
    BufferedReader in = new BufferedReader(new InputStreamReader(ins));
    while((line = in.readLine()) != null){
        //System.out.println(name + " " + line);
        System.out.println(line);
    }        
}
to be called by these lines
try{
            runProc("javac sample.java");
            runProc("java sample");
            } catch (Throwable t){
             t.printStackTrace();}
Now, what I want to be able to do is, after the javac command, I'll run "java sample" inside a terminal. I understand that going "cmd start java sample" only returns what is supposedly displayed on the cmd to the Greenfoot terminal. And by going "cmd start" ill just invoke a new cmd on the dir where my greenfoot project is at. (Since the target of our project is to teach Java to kids, I think it would be better if we need not include a documentation on how to manually run java on the console.) I am on windows 7. If anyone can point me to the right track or maybe give me a hint as to how ill be able to start my cmd already with java filename.. Please and Thank you
You need to login to post a reply.