DOS 7.1 Use command output in variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sebas
Posts: 3
Joined: 03 Aug 2011 08:18

DOS 7.1 Use command output in variable

#1 Post by sebas » 03 Aug 2011 08:25

Hi,
Is it possible to use the output that is echoed by a command in DOS 7.1?. The for /f does not exist in 7.1.
I use the find command:
type file.txt|find "string" /c
It returns me a number.
I can send the result to another file like this
find "string" < inputfile > outpufile
But i need to send it to a variable.
Thanks for the help.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: DOS 7.1 Use command output in variable

#2 Post by Ed Dyreen » 03 Aug 2011 11:39

'
You could use SET2VAR.EXE

Code: Select all

   "%Drive.RAM%\SHOWMENU.EXE" Finding MAC Address
   rem ::(
      "%Drive.RAM%\NBMAC.EXE"
      "%Drive.RAM%\NBMAC.EXE" |> "%Drive.RAM%\OUT.BAT" "%Drive.RAM%\SET2VAR.EXE" MAC
   rem    ::
      call "%Drive.RAM%\OUT.BAT"
   rem ::)

$MAC now contains the result, in your situation you'll need type "$file" |set2var $var

SET2VAR.EXE can be found inside the netbootdisk http://netbootdisk.com/ :)

sebas
Posts: 3
Joined: 03 Aug 2011 08:18

Re: DOS 7.1 Use command output in variable

#3 Post by sebas » 04 Aug 2011 07:51

This seems to be totally what i'm looking for but i am not able to make it work.
I use this simple command:
type allo.txt|find "1.10" /c|set2var cnt
it work and echo @set cnt=2 but im in the same problem as before, i still can't use the value of cnt in a command.
I need to write:
Type cnt
to see the value.
the command echo %cnt% tell me echo is on instead of 2.
I'm new to Dos so i probably did something wrong but can't figure it out.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: DOS 7.1 Use command output in variable

#4 Post by Ed Dyreen » 04 Aug 2011 08:03

'
The guy from NetBootDisk wrote Set2Var himself, he also ownes the copyright.
What you are looking for is explained at his site.

Code: Select all

SET2VAR v0.2 - Freeware - By Brad Driver - Google 'SET2VAR.EXE' for help!

For helping with piping the output of a program to an environment variable
eg: >SomeApp.exe|set2var.exe VarName>TempBatchFile.bat
Druk op een toets om door te gaan. . .
set2var was designed in such a way that it writes set $var=? to TempBatchFile.bat.
The only thing you need to do now is call TempBatchFile.bat.

It's really easy to write your own Set2Var.EXE application. It only takes about 5 assembly instructions.
Unfortunately I have zero knowledge of the x86 instruction set.

I hope to learn this myself someday or be teached by someone.
Does anyone know a good x86 ASM forum ?

Beware, DOS 7.1 was designed to do simple scripting only. Did you know it supports QBASIC.
The MS installer was written in it. It's a powerfull language and a lot of fun.
If you like scripting, QBASIC supports it :)
Last edited by Ed Dyreen on 04 Aug 2011 14:17, edited 3 times in total.

sebas
Posts: 3
Joined: 03 Aug 2011 08:18

Re: DOS 7.1 Use command output in variable

#5 Post by sebas » 04 Aug 2011 11:55

Good. :D You are awesome so fast answer and you solved my problem.
Thanks a lot.

Post Reply