lundi 20 avril 2015

Java interact with cmd

Hi and sorry for my english...

I must interact in a windows terminal with a jframe...

This is code to start the cmd

     try {

        String command = "file.exe";

        Runtime rt = Runtime.getRuntime();
        Process pr = rt.exec(command);

        input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
        output = pr.getOutputStream();

        String line=null;

        while((line=input.readLine()) != null) {
            System.out.println(line);
        }

        int exitVal = pr.waitFor();
        System.out.println("Exited with error code "+exitVal);

    } catch(IOException | InterruptedException e) {
        System.out.println(e.toString());
        e.printStackTrace(System.out);
    }   

Then the jframe starts when exit from cmd line...

I need to start this in background and passing the output to the window...

How to ?

Aucun commentaire:

Enregistrer un commentaire