Jump to content

How to use Windows DISKPART tool by code / java or c++;

Hi guys,

 

please, can anyone help me ? 

 

I am having this wierd problem. I want to use DISKPART which is tool in windows used to manage partitions e.t.c. of your drives, from java, programatically.

The problem is , how to open DISKPART and insert command "select disk 1" and then "clean". (example);

 

Problem comes when DISKPART is opened from java in new window, and seems no to accept any other commannds.

 

Here's the code.

	 ProcessBuilder builder = new ProcessBuilder(			            "cmd.exe","/C diskpart /s select disk 1", "clean");			        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);			        }			    }

I tried multiple ways, this is the default way. Thanks a lot :)

Link to post
Share on other sites

If you wanted to use diskpart, why are you trying to start cmd? This is what I would do (if your parameter syntax is correct):

ProcessBuilder builder = new ProcessBuilder(			            "diskpart.exe","select disk 1", "clean");

When you type diskpart in a cmd shell, you are telling cmd.exe to execute diskpart.exe and hookup stdin and stdout (from what I can tell, I don't really use this tool often). So I am pretty sure this should work for you.

| CPU: 2600K @ 4.5 GHz 1.325V | MB: ASUS P8Z68-V pro | GPU: EVGA GTX 480 clk 865/mem 2100 | RAM: Corsair Vengeance 1600 MHz CL9 | HDD: Muskin Chronos Deluxe 240GB(win8) && ADATA SX900 120 GB(ubuntu 12.04) | PSU: Seasonic x760 |

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×