1

I have a quick question: I am trying to call the following command line from a java application C:/phantomjs/phantomjs chart/chart.js

I tried doing:

public static void go3(){
    Runtime rt=Runtime.getRuntime();
    try{
        final Process pr=rt.exec("cmd C:/phantomjs/phantomjs chart/chart.js");
        final int exitCode=pr.waitFor();
        if(exitCode!=0){ throw new RuntimeException("program didnt exit with 0, but with "+exitCode); }
        // System.out.println(pr.toString());
        // int exitStatus=pr.waitFor();
    }catch(IOException e){
        // TODO Auto-generated catch block
        e.printStackTrace();
    }catch(InterruptedException e){
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("done");
}

but I get exit code -1. I looked at various tutorials/question on stackoverflow but they all run trivial examples and I am struggling to understand how to write the part inside .exec("what goes here?")

1 Answer 1

2

Found the answer:

public static void go4(){
    String[] command={"cmd","/k","cd /phantomjs&&phantomjs chart/chart.js"};
    Process p;
    try{
        p=Runtime.getRuntime().exec(command);
        PrintWriter stdin=new PrintWriter(p.getOutputStream());
        stdin.close();
        int returnCode;
        returnCode=p.waitFor();
        System.out.println("Return code = "+returnCode);

    }catch(IOException e1){
        e1.printStackTrace();

    }catch(InterruptedException e){
        e.printStackTrace();
    }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.