0

Can anyone please suggest me how can I get the value of 9 from the below output.

"Version

"9.0.56336

I know that we need to parse the output and get that value. But, am not succeded to get that.

Thanks In Advance.

3
  • Welcome on Stackoverflow. What have you tried? Did something almost work? What error message do you get? Is the text in a file or is it the output of a program? Commented May 13, 2014 at 14:00
  • This is the command I used to get the version and its value. FOR /F "tokens=* delims= " %%a IN ('"wmic product where "Name like 'Microsoft Visual C++ 2005 Redistributable'" get version"') do echo "%%%a" Commented May 13, 2014 at 14:09
  • Here Am unable to assign the output to a variable, this is the command I used to set the output. for /f "tokens=3 delims=." %%a in ('wmic product where "Name like 'Microsoft Visual C++ 2005 Redistributable'" get Version') do set fine="%%%a" echo fine:%fine% Commented May 13, 2014 at 14:12

1 Answer 1

1
@ECHO OFF
SETLOCAL
SET "fine="9.0.56336"
ECHO %fine%
SET "fine=%fine:"=%"
ECHO %fine%
FOR /f "delims=." %%a IN ("%fine%") DO SET "fine=%%a"
ECHO %fine%

GOTO :EOF

Your ...set fine="%%%a" echo fine:%fine%

should be on two separate lines

...set fine="%%a"
echo fine:%fine% 

and there should be two, not three %s

This does set fine to the last line (I believe - haven't got the same installation, so I can't test it)

If you indeed have "9.0.56336 as your data content, then the above processing should get the 9.

Sign up to request clarification or add additional context in comments.

4 Comments

Hi Magoo, your code is working fine , but here my trouble is after executing the below line version is not set to the fine variable. for /f "tokens=3 delims=." %%a in ('wmic product where "Name like 'Microsoft Visual C++ 2005 Redistributable'" get Version') do set fine="%%a"
Its setting some junk value "56336 ".
use tokens=1 and it should get the 9
Can't reproduce your problem. Try editing-in the exact response you are seeing ...do set fine="%%a" [new line] ECHO fine:%fine% BTW - set fine="%%a" and set "fine=%%a are vastly different. If %%a contains the string something then the first will set fine to the value "something" whereas the second will set fine to something - the first is quoted, the second, not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.