“Java Run CMD” Kode Jawaban

Java Run CMD

public void excCommand(String new_dir){
    Runtime rt = Runtime.getRuntime();
    try {
        rt.exec(new String[]{"cmd.exe","/c","start"});

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Java Run CMD


import java.io.*;

public class CmdTest {
    public static void main(String[] args) throws Exception {
        ProcessBuilder builder = new ProcessBuilder(
            "cmd.exe", "/c", "cd \"C:\\Program Files\\Microsoft SQL Server\" && dir");
        builder.redirectErrorStream(true);
        Process p = builder.start();
        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while (true) {
            line = r.readLine();
            if (line == null) { break; }
            System.out.println(line);
        }
    }
}

Cruel Cod

Cara menjalankan java di cmd

// i have a file name : demo.java
public class demo{
  public static void main(String[]args){
    System.out.println("hello world");
  }
}
//open cmd or terminal on folder and then : java demo.java 
Itchy Iguana

Jawaban yang mirip dengan “Java Run CMD”

Pertanyaan yang mirip dengan “Java Run CMD”

Lebih banyak jawaban terkait untuk “Java Run CMD” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya