• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2192
  • Last Modified:

Assign variable on DOS

I want to assign a value to a variable on DOS enviroment but I can't

Ex.
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%
Echo.

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 cmoreno@tatungmx.com.
Regards
0
jtsokanis
Asked:
jtsokanis
  • 3
  • 3
  • 2
  • +2
1 Solution
 
InteractiveMindCommented:
Could you please provide your code?
0
 
jtsokanisAuthor Commented:
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



0
 
InteractiveMindCommented:
does this work:

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

??
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

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

Regards;
0
 
SteveGTRCommented:
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,
Steve
0
 
For-SoftCommented:
Looks like Jtsokanis wants the script to run in clean DOS enviroment. So, Windows XP/2000 syntax will not be a solution to him.
0
 
For-SoftCommented:
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
ECHO %MODEL%
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.
0
 
For-SoftCommented:
Oh.
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.
0
 
brianadkinsCommented:
For-Soft,

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

-Brian
0
 
SteveGTRCommented:
For-Soft offers a good solution.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now