I’m trying to extract the sent bytes from a shell on Windows OS, the command I use is “netstat -e | findstr Bytes”. Running this command, I get in return this result:
C:\Users\gabri>netstat -e | findstr Bytes
Bytes 418488604 3296672780
More exactly, I only need the 2nd number. How would you guys do it?
There are only two numbers in your sample output though. Are you looking for “3296672780” or something else?
2nd number yes, sorry I am tired
From that string, I need to extract only the 2nd number, every time I run the command.
If it’s always in that format then:
var parts() as string = sh.Result.Trim.Split( " " )
var myNum as integer = parts.Pop.ToInteger
I’m assuming that’s a space between numbers, and the last part will always be the number you’re looking for.
The forum formatted the string and only added 1 space.
In reality, the string returned by the shell has more spaces.
That code should still work, as long as they are spaces and not something else like tabs.
For some reason if I use like you suggested “var myNum as integer = parts.Pop.ToInteger” Xojo returns a -random_number…
What works is: “Var myNum As String = parts.Pop” … strange
Thank you @Kem_Tekinay for your solution.
That is odd, but I’m glad some part of it worked for you.
parts.Pop.ToInteger → integer overflow
resulting in a negative number.
That’s the stronger reason I tend to avoid shell calls when there are declares available for the same command. You’re never sure the format is always the same (especially when the command takes the available window’s width in the Terminal/command prompt) and the number of space may vary. What if @Gabriel_L wanted to get the first of the two numbers? Or if the command returned several number (even if you know how many beforehand) and they all have different count of spaces between them?
Too much unreliable, IMO, these shell results…