rsk82
rsk82

Reputation: 29447

can get out some data from call to a label in cmd file?

this example isn't working:

call :testcall > %output%
goto :eof

:testcall
  echo return
goto :eof

:eof

I need that %output% contained return string.

Upvotes: 0

Views: 110

Answers (3)

dbenham
dbenham

Reputation: 130929

It works as long as variable output is defined properly.

@echo off
set output=test.txt
call :testcall > %output%
goto :eof

:testcall
  echo return
goto :eof

:eof

Edit

I think I may have mis-interpreted the question. I assumed the OP was attempting to create a file. But I believe jeb's answer has the correct interpretation, along with a good answer.

Upvotes: 1

jeb
jeb

Reputation: 82438

I assume, that you want the text return in the variable output, not in the file named output!?

There are two common ways to get this:
For/F and set/p

@echo off
call :testcall > outfile.tmp
< outfile.tmp set /p myVariable=
set myVar
goto :eof

:testcall
  echo return
goto :eof

set/p can also read more than one line, when you enclose it into parenthesis

@echo off
call :testcall2 > outfile.tmp
< outfile.tmp (
   set /p myVariable1=
   set /p myVariable2=
   set /p myVariable3=
)
set myVar
goto :eof

:testcall
  echo return line1
  echo content2
  echo content3
goto :eof

With For/F you could also read data into variables, and you don't need any temporary file.

@echo off
for /F "delims=" %%A in ('echo return') DO set myVariable=%%A
set myVar

Upvotes: 2

PA.
PA.

Reputation: 29369

try

(
     call :testcall
) >output.txt

Upvotes: 2

Related Questions