0

I have created this code and I cannot do so when I type some text to username and yearsoflife the text to be exported in a .txt file.

@echo off
color 0a
echo.
echo.
echo    Please insert the following
echo.
echo.
echo.
set /p username=name:
set /p yearsoflife=age:
%username% > name.txt
%yearsoflife% > yourage.txt
3
  • 2
    (Echo=%username%)>"name.txt", (Echo=%yearsoflife%)>"yourage.txt". Commented Dec 9, 2018 at 18:34
  • Thanks, that worked perfectly. I have realisted that i need them both in the same txt file any suggestions ? Commented Dec 9, 2018 at 19:11
  • 1
    Nevermind, i figured it out just had to put (Echo=%username%,%yearsoflife%)>"file.txt" , thanks for your help ! Commented Dec 9, 2018 at 19:19

1 Answer 1

1

Here is one possible solution:

@echo off
color 0a
echo.
echo.
echo    Please insert the following
echo.
echo.
echo.
set /p _username=name: 
set /p yearsoflife=age: 
(echo=%_username%) > name.txt
(echo=%yearsoflife%) > yourage.txt

You were not so clear in your question; you referenced that you want both variable contents in one textfile. So, for this you can try (double the > symbol):

@echo off
color 0a
echo.
echo.
echo    Please insert the following
echo.
echo.
echo.
set /p _username=name: 
set /p yearsoflife=age: 
(echo=%_username%) >> your_name.txt
(echo=%yearsoflife%) >> your_name.txt

Note: Change of set /p username=name: line was just not to confuse this username variable with username environment variable!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.