Assign variable on DOS

Posted on 2005-04-14
Last Modified: 2008-01-09
I want to assign a value to a variable on DOS enviroment but I can't

I have a program called cpc_dmi.exe it gives me the follow information

SerialNumber:      MXK5130N7G
HWBOM:             101
RIN:               NA52
ProductNumber:     PW636AA
LanguageCode:      ABA
ModelNumber:       A1017C

I want to keep on a variable the model as below:
Model= A1017C

I can do:
@echo off
Echo Model: %model%

But I can't keep on a variable to use on a batch file, I can do it with For command but it didn't work on DOS just on W2K

If you have some information about please let me know and send email to me at
Question by:jtsokanis
    LVL 25

    Expert Comment

    Could you please provide your code?

    Author Comment

    For a single line I do the follow:

    If I run the follow line:
    cpc_dmi /read | find /i "ModelNumber" >model.txt

    it gives me the
    ModelNumber:       A1017C
    inside model.txt

    I need to keep this value in a variable in order to use in another batch file

    LVL 25

    Expert Comment

    does this work:

    for /f "tokens=2 delims= " %%T in (model.txt) do set Model=%%T

    LVL 25

    Expert Comment

    I've got to now, I will be back to help further in the morning (GMT).

    LVL 30

    Expert Comment

    Try this:

    @echo off

    for /F "tokens=2 delims= " %%a in ('cpc_dmi /read^|findstr ModelNumber') do set model=%%a

    echo Model: %model%

    Good Luck,
    LVL 10

    Accepted Solution

    Looks like Jtsokanis wants the script to run in clean DOS enviroment. So, Windows XP/2000 syntax will not be a solution to him.
    LVL 10

    Expert Comment

    In old DOS enviroment the "for /F " sysntax will not work, so it will be necesary to get around it.
    --------------- getmodel.bat
    ECHO SET MODEL=%%2>setmodel.bat
    REM cpc_dmi /read | find /i "ModelNumber" >model.txt
    ECHO ModelNumber:       A1017C>model.txt
    copy setmodel.txt+model.txt model.bat
    call model.bat
    del setmodel.bat
    del model.txt

    In order to work the getmodel.bat file needs a setmodel.txt file with
    "call setmodel.bat " inside without " character and without enter or carriage return character at the end of the setmodel.txt file.
    The "copy setmodel.txt+model.txt model.bat" comand will create model.bat file with
    "call setmodel.bat ModelNumber:       A1017C" line inside.
    This will call "SET MODEL=%2" command from setmodel.bat file created by
    "ECHO SET MODEL=%%2>setmodel.bat" command from getmodel.bat file.

    It is not a simple solution, but it should work in old DOS without "for /F" syntax support.
    LVL 10

    Expert Comment

    I used the "ECHO ModelNumber:       A1017C>model.txt" line for testing. Delete the line and remove REM from "REM cpc_dmi /read | find /i "ModelNumber" >model.txt" line.
    It works correctly in Windows 95 DOS version. So it should work in older versions.
    LVL 5

    Expert Comment


     I would have never thought of that...  great idea.

    LVL 30

    Expert Comment

    For-Soft offers a good solution.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
    YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT ( The crux of this batch f…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now