Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I pass parameter from my batch script to diskpart.exe?

Batch file:

DISKPART /s diskpart.txt F

This is giving me an error:

Diskpart unable to process parameter

diskpart.txt:

SELECT DISK 3
ATTRIBUTES DISK CLEAR READONLY
ONLINE DISK
SELECT DISK 3
CLEAN
CREATE PARTITION PRIMARY
ASSIGN LETTER %1
EXIT

Also, how to read it from diskpart.exe?

question from:https://stackoverflow.com/questions/65943259/how-to-pass-to-and-read-from-diskpart-exe

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
283 views
Welcome To Ask or Share your Answers For Others

1 Answer

As questions on SO deal with only a single specific issue, I'll attempt to offer a solution for the first question only, which is directly related to your code.

Here's my suggested replacement for what you're using:

@CALL :SUB F
@EXIT /B
:SUB
@(  ECHO SELECT DISK 3
    ECHO ATTRIBUTES DISK CLEAR READONLY
    ECHO ONLINE DISK
    ECHO SELECT DISK 3
    ECHO CLEAN
    ECHO CREATE PARTITION PRIMARY
    ECHO ASSIGN LETTER %1
    EXIT) | %SYSTEMROOT%SYSTEM32DISKPART.EXE

Please note, that I am not recommending that anyone tests this code, as it will destroy data, on any online Disk 3 on their system.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...