0
votes

I have a dos batch file.

mycommand.exe>c:\temp
find /B Serv c:\temp>c:\temp2
set /p var1=<c:\temp2
SET var2=%var1:~-7%
echo %var2%

This is only DOS, not windows environment.

The problem is that, the batch file output is: "Echo is ON". Can't echo the VAR2 variable.

mycommand.exe is a simple app. Not important.

> type c:\temp"
VERSION 45.2
TAG1 NUMBER is 1234567
Serv NUMBER is 9654754

> type c:\temp2
c:temp Serv NUMBER is 9654754

What can I do, If I would like echo the VAR2 variable? I can't use "setlocal enabledelayedexpansion" because setlocal "Command or filename not recognized".

Edit: What am I want exactly? I would like to ECHO mycommand.exe output 3rd line last 7 characthers. Thats all.

1
DOS set command does not support /p. It also doesn't support substitution It's only set variable=valueStephan
Does DOS have a /B on FIND, also, now that I think about it?Joe
find has no /B neither in DOS nor in Cmd. (you think of findstr, which has the /b, but it's not available in DOS)Stephan

1 Answers

1
votes

"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:\temp.txt
find "Serv " c:\temp.txt>c:\temp2.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)