How do i get error code from diskpart in batch file?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rusty_uk
Posts: 5
Joined: 18 Jan 2017 04:00

How do i get error code from diskpart in batch file?

#1 Post by rusty_uk » 18 Jan 2017 06:58

Hi

I have an automation batch script that calls diskpart and does things to disks. I need the script to pass success or error codes on end but cannot work out how to do it.

An example would be that im trying to expand a disk using diskpart but there is no space available to do this. I get a message stating that there is not available space, but it does not give me an error code. Or if it is, im not reading it correctly.

Any help would be greatly appreciated here.

Thanks

R

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: How do i get error code from diskpart in batch file?

#2 Post by Squashman » 18 Jan 2017 07:22

I realize you have code in your other post but you should still post all relevant code in all your questions so people do not have to search and destroy for what you are trying to do.

rusty_uk
Posts: 5
Joined: 18 Jan 2017 04:00

Re: How do i get error code from diskpart in batch file?

#3 Post by rusty_uk » 18 Jan 2017 09:11

Silly me. I was supposed to add this :)

Code: Select all

setlocal EnableDelayedExpansion
set tempfile="c:\windows\temp\diskpart_create_tmp.txt"
set listfile="C:\windows\temp\diskpark_listdisks_tmp.txt"
set otherfile="C:\windows\temp\diskpart_listdisks_output.txt"
ECHO list volume >!listfile!
echo off
diskpart /s !listfile! > !otherfile!
    for /F "skip=8 tokens=2-6" %%a in (C:\windows\temp\diskpart_listdisks_output.txt) do (
        @echo     %%a %%b %%c
      @if /I "%%b" == "%1" (
         echo Extend %%b
         echo select volume %%a >!tempfile!
         echo extend >>!tempfile!
         diskpart /S !tempfile!
      )
    )   
del !tempfile!
del !listfile!
del !otherfile!

pieh-ejdsch
Posts: 240
Joined: 04 Mar 2014 11:14
Location: germany

Re: How do i get error code from diskpart in batch file?

#4 Post by pieh-ejdsch » 18 Jan 2017 13:50

The issue is: the list is not subdivided properly.
If the Volumename is 2-part the allocation becomes wrong. instead, you must read in the whole line and assign this into a variable - then must be subdivided in the suitable offset. With the help of these limbs you can process the mistake after a condition.

Phil

rusty_uk
Posts: 5
Joined: 18 Jan 2017 04:00

Re: How do i get error code from diskpart in batch file?

#5 Post by rusty_uk » 19 Jan 2017 07:08

Phil

Thanks for responding, but im not 100% sure what you mean. Unfortunately, im not a native Batch scripter.

Thanks

Rusty

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: How do i get error code from diskpart in batch file?

#6 Post by ShadowThief » 19 Jan 2017 21:00

rusty_uk wrote:Phil

Thanks for responding, but im not 100% sure what you mean. Unfortunately, im not a native Batch scripter.

Thanks

Rusty

Spaces in file names break everything; avoid them at all costs.

Post Reply