jtsokanis
asked on
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
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
Could you please provide your code?
ASKER
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
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
does this work:
for /f "tokens=2 delims= " %%T in (model.txt) do set Model=%%T
??
for /f "tokens=2 delims= " %%T in (model.txt) do set Model=%%T
??
I've got to now, I will be back to help further in the morning (GMT).
Regards;
Regards;
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
@echo off
for /F "tokens=2 delims= " %%a in ('cpc_dmi /read^|findstr ModelNumber') do set model=%%a
echo Model: %model%
Good Luck,
Steve
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
--------------- 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.
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.
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.
For-Soft,
I would have never thought of that... great idea.
-Brian
I would have never thought of that... great idea.
-Brian
For-Soft offers a good solution.