0
I am retrieving disk information via JavaScript with the wmic
statement, wmic logicaldisk get freespace,name,size,volumename
, which produces the following output, but in a single string.
"FreeSpace Name Size VolumeName "
"560232755200 C: 999526756352 System "
"999369699328 D: 999558213632 SSD "
"1511570386944 E: 8001545039872 Get "
"4620751712256 F: 8001545039872 BR "
"788449492992 G: 4000650883072 Seen "
"2296009408512 H: 4000768323584 Seen 2 "
"3594248679424 I: 8001545039872 2160 "
"3507750227968 J: 8001545039872 1080 "
"945300619264 K: 999625322496 Trailers "
I parse the above output with the following JavaScript.
window.onload = function(){
const cp = require('child_process')
let drives
cp.exec('wmic logicaldisk get freespace,name,size,volumename', (error, stdout)=>{
drives = stdout.trim().split('\r\r\n')
.map(value => value.trim().split(/\s{2,0}/))
.slice(1)
})
}
That JavaScript already produces my desired output. It produces an array of nested arrays. Each row of information in the command prompt output corresponds to a nested array. Each nested array has four values that correspond to the originally queried data points.
[
["560232439808", "C:", "999526756352", "System" ]
["999369699328", "D:", "999558213632", "SSD" ]
["1511570386944", "E:", "8001545039872", "Get" ]
["4620751712256", "F:", "8001545039872", "BR" ]
["788449492992", "G:", "4000650883072", "Seen" ]
["2296009408512", "H:", "4000768323584", "Seen 2" ]
["3594248679424", "I:", "8001545039872", "2160" ]
["3507750227968", "J:", "8001545039872", "1080" ]
["945300619264", "K:", "999625322496", "Trailer" ]
]
I am wondering whether or not there is a way to similarly parse the information, but with command prompt instead?
omg u know what. i didnt even think of that. i could just edit my regex query to
/\s{2,}/
, which should work like a charm. thanks so much dude. do you know if theres a way to achieve the same result purely with thewmic
or command prompt statement? – oldboy – 2019-12-31T19:21:20.060No sorry, all i can think of right now is that your regex was catching the white spaces which was causing the issue, i was working a bit revised regex string since mine was messy, but with a improved regex you should be able to refine the output and what gets put into the array
heres a slightly less messy regex string i made which ignores whitespace and should individually catch the data.
/(\d)(?:\w)(\w:)(\d)(\w( )?)/ – SomeRandomOwl – 2019-12-31T19:28:39.090
your regex does not work. are you sure youre using JS regex? anyways, ive modified my regex statement to
/\s{2,}/
which works like a charm and shouldnt have any problems. im going to leave the question open to try and get some more answers, but if it doesnt receive any and you remind me in a day or two ill mark your response as the answer!! thanks again <333 – oldboy – 2019-12-31T19:37:13.530