Listing virtual disks in Java

96 views Asked by At

Is there a way to list all virtual disks attached using Java? I've tried using ProccessBuilder to open diskpart and running command and then using InputStreamReader, save lines into an array to later extract vhd name. But after running diskpart command my program freezes.

try {
    commands.add("cmd.exe");
    commands.add("start");
    commands.add("diskpart");
    commands.add("list vdisk");

    ProcessBuilder builder = new ProcessBuilder(commands);
    Process p = builder.start();

    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }
    br = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    while ((line = br.readLine()) != null) {
        System.out.println(line);
    }
} catch (IOException e) {
    e.printStackTrace();
}
0

There are 0 answers