1

I have tried taking value from stdin < but it only holds first line.

set /p var=<test.txt
echo %var%

I need entire content of file in the variable. is it possible ?

once the variable is set. can I pass it to html page and display it in textarea ?

Rithesh Bhat
  • 127
  • 1
  • 12
  • Possible duplicate of [Batch Script : Read all content from text flie in single variable](https://stackoverflow.com/questions/47551175/batch-script-read-all-content-from-text-flie-in-single-variable) – aschipfl Dec 14 '17 at 09:31

1 Answers1

2

If you absolutely must use a batch file for some reason, the following code will help you accomplish your task.

@echo off && setlocal enabledelayedexpansion

set NL=^



for /f "delims=" %%i in (myfile.txt) do set fc=!fc!%%i%NL%

What is happening is the set statement is using a "bug" in the escape funcionality to store a newline in the variable NL. The two blank lines afterward are indeed necessary. The last line iterates through the file and appends each line to the variable fc with a trailing newline.

As far as putting the contents of the variable in a text field, this could be accomplished by many means, one being to write the html file upto and including the first textarea tag, then writing the contents of the variable, and then writing the rest of the html file.

cure
  • 2,588
  • 1
  • 17
  • 25