Jump to content

Read CMD Display Text


Sudiro
 Share

Recommended Posts

Dear All..

Found this script in forum..

#include <Constants.au3>
#RequireAdmin

$hPrDiskPart = Run(@ComSpec & " /k " & "diskpart", @SystemDir,@SW_HIDE,$STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($hPrDiskPart, "list disk" )
StdinWrite($hPrDiskPart)
Local $data
While True
    $data &= StdoutRead($hPrDiskPart & @CRLF)
   If @error Then ExitLoop
    Sleep(25)
WEnd

MsgBox(0, "", "List Disk: "  & @CRLF & $data) ; I want This MsgBox Only Show Disk### (Disk0, Disk1,...)

 

How to make msgbox only show disk number..? Not show all text in dispart /list

Edited by Sudiro
Link to comment
Share on other sites

May be this help you 

 

#include <Constants.au3>
#include <Array.au3>

#RequireAdmin

$hPrDiskPart = Run(@ComSpec & " /k " & "diskpart", @SystemDir,@SW_HIDE,$STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($hPrDiskPart, "list disk" )
StdinWrite($hPrDiskPart)
Local $data
While True
    $data &= StdoutRead($hPrDiskPart & @CRLF)
   If @error Then ExitLoop
    Sleep(25)
WEnd
$array = StringRegExp($data,"\w[disk]+\s+\d",1)
_ArrayDisplay($array)

 

Link to comment
Share on other sites

7 hours ago, Muhammad_Awais_Sharif said:

May be this help you 

 

#include <Constants.au3>
#include <Array.au3>

#RequireAdmin

$hPrDiskPart = Run(@ComSpec & " /k " & "diskpart", @SystemDir,@SW_HIDE,$STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($hPrDiskPart, "list disk" )
StdinWrite($hPrDiskPart)
Local $data
While True
    $data &= StdoutRead($hPrDiskPart & @CRLF)
   If @error Then ExitLoop
    Sleep(25)
WEnd
$array = StringRegExp($data,"\w[disk]+\s+\d",1)
_ArrayDisplay($array)

 

Only Show Disk0, If Insert USB/flashdisk, Disk1, Disk2 Not show in array..

Link to comment
Share on other sites

change in this line :P 

$array = StringRegExp($data,"\w[disk]+\s+\d",1)

to this
 

$array = StringRegExp($data,"\w[disk]+\s+\d",3)


Full Code Working for me 


 

#include <Constants.au3>
#include <Array.au3>

#RequireAdmin

$hPrDiskPart = Run(@ComSpec & " /k " & "diskpart", @SystemDir,@SW_HIDE,$STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($hPrDiskPart, "list disk" )
StdinWrite($hPrDiskPart)
Local $data
While True
    $data &= StdoutRead($hPrDiskPart & @CRLF)
   If @error Then ExitLoop
    Sleep(25)
WEnd
$array = StringRegExp($data,"\w[disk]+\s+\d",3)
_ArrayDisplay($array)

 

Link to comment
Share on other sites

On 21/10/2016 at 8:15 AM, Muhammad_Awais_Sharif said:

change in this line :P 

$array = StringRegExp($data,"\w[disk]+\s+\d",1)

to this
 

$array = StringRegExp($data,"\w[disk]+\s+\d",3)


Full Code Working for me 


 

#include <Constants.au3>
#include <Array.au3>

#RequireAdmin

$hPrDiskPart = Run(@ComSpec & " /k " & "diskpart", @SystemDir,@SW_HIDE,$STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($hPrDiskPart, "list disk" )
StdinWrite($hPrDiskPart)
Local $data
While True
    $data &= StdoutRead($hPrDiskPart & @CRLF)
   If @error Then ExitLoop
    Sleep(25)
WEnd
$array = StringRegExp($data,"\w[disk]+\s+\d",3)
_ArrayDisplay($array)

 

Thank's Sharif.. 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...