简体   繁体   中英

Execute commands in cmd using Java

I am using the following code to run the cmd.exe and the cmd window appears which is fine.

Runtime runtime = Runtime.getRuntime();
    try {
        Process p = runtime.exec("cmd.exe /c start");
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

image 1

My question is that how can I run the following command on the cmd before it appears using java

ghci test.hs

my target is to make the command line looks like the following image once it appears

imag2

run

Runtime runtime = Runtime.getRuntime();      
try { 
    Process p = runtime.exec("start cmd.exe /k \"ghci.exe test.hs\""); 

} catch (IOException ex) {
 Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); 
}

referens http://ss64.com/nt/cmd.html

more info at How to open the command prompt and insert commands using Java?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM