简体   繁体   中英

BATCH - How to echo a line with a set /P command to another file

I'm writing a batch file which gathers some enviromental data and uses it to build another batch file. I have a problem with passing the line which contains a set /P command using an echo command.

My code:

echo smthnsmthn >> batch.bat
echo set /P var=<file.txt >> batch.bat
echo smthnsmthn >> batch.bat

The problem is that the line containing the set /P command is missing in the output batch.bat file.

I've tried to replace the set command with

echo for /f "delims=" %%%x in (file.txt) do set "var=%%%x" >> batch.bat

but the result is the same.

Thanks for help.

(   echo smthnsmthn
    echo set /P var=^<file.txt
    echo smthnsmthn
) > batch.bat

You need to escape the < so it is not seen as an input redirect in the generating batch, but as normal character

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM