"good old DOS" is old, but not very good.
Your problem can be solved, basicly by building a temporary .bat file.
It's described in detail here:
https://support.microsoft.com/en-us/kb/66292
I have no DOS available, so I can't test, but this should work for you:
mycommand.exe>c:emp.txt
find "Serv " c:emp.txt>c:emp2.txt
REM init.txt should already exist
REM to create it:
REM COPY CON INIT.TXT
REM SET VARIABLE=^Z
REM ( press Ctrl-Z to generate ^Z )
REM
REM also the file "temp2.txt" should exist.
copy init.txt+temp2.txt varset.bat
call varset.bat
for %%i in (%variable%) do set numb=%%i
echo Server number is: %numb%
REM just because I'm curious, does the following work? :
set var2=%variable%
echo var2 is now %var2%
The manual creation of init.txt
has to be done once only, if you can live with, that it always creates a variable with the same name (therefore the last two lines, so you could use the same init.txt over and over again - please feedback, whether it works - I'm quite curious)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…