pipe result into a variable...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
catalinnc
Posts: 39
Joined: 12 Jan 2015 11:56

pipe result into a variable...

#1 Post by catalinnc » 04 Dec 2016 12:57

hi...


for now i use this to set a variable from a tool output...

Code: Select all

tool.exe some.file > result.txt 
set /p _var=< result.txt
del result.txt


can this be done without the "middle man" result.txt?

meaning to pipe the tool.exe output into _var?


thanks...
_

jfl
Posts: 226
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: pipe result into a variable...

#2 Post by jfl » 04 Dec 2016 14:49

This should do it in simple cases:

Code: Select all

for /f "delims=" %%l in ('tool.exe some.file') do set _var=%%l

Note however that if your tool may output an empty line, or one line with just spaces, the above command will not capture it. A more complex code would be needed in this case.

catalinnc
Posts: 39
Joined: 12 Jan 2015 11:56

Re: pipe result into a variable...

#3 Post by catalinnc » 05 Dec 2016 13:10

thanks a lot...

is working great...
_

Post Reply