Page 1 of 1
User Input
Posted: 20 May 2010 15:52
by sp11k3t3ht3rd
Okay this may sound like a stupid question but how can you ask the user to type something and then have what they typed be put into a .txt file? i know the command for user input is:
but when I type this code after that:
It creates the .txt file and then says that what ever the user typed is not a valid command. PLEASE HELP!
Re: User Input
Posted: 20 May 2010 16:01
by aGerman
You need the command ECHO for outputting a variable value.
Regards
aGerman
Re: User Input
Posted: 20 May 2010 16:09
by sp11k3t3ht3rd
Thanks!! I have another question though. How can you make multiple lines get copied in the file? Like I want to be able to have text be entered on the second line in the .txt file.
Re: User Input
Posted: 20 May 2010 16:22
by aGerman
> is for NEW
>> is for APPEND
Code: Select all
@echo off &setlocal
set /p "line1=1st line: "
set /p "line2=2nd line: "
set /p "line3=3rd line: "
>test.txt echo.%line1%
>>test.txt echo.%line2%
>>test.txt echo.%line3%
Regards
aGerman
Re: User Input
Posted: 20 May 2010 16:24
by 1+2=46
for the first line.
for the other lines.
Example:
The file "test.txt" would be like this:
1
2
If you then would want to add another line to it you would have to put...
... which would make the file be like this:
1
2
3
So, the code "echo %something%>>%some file%" will add the %something% to the end of the %some file%.
Re: User Input
Posted: 20 May 2010 16:28
by sp11k3t3ht3rd
@aGerman That only made 2 lines... and what does
do?
Re: User Input
Posted: 20 May 2010 16:34
by 1+2=46
Use mine code instead if you are having problems with aGerman one's, though his is better than mine, I guess.
Re: User Input
Posted: 20 May 2010 16:40
by sp11k3t3ht3rd
I don't know why but this seems to work just fine:
Code: Select all
@echo off
set /p line1= line:
echo %line1%>test1.txt
set /p line2= line:
echo %line2%>>test1.txt
set /p line3= line:
echo %line3%>>test1.txt
pause
Thanks for all the help!
Re: User Input
Posted: 20 May 2010 16:43
by aGerman
sp11k3t3ht3rd wrote:@aGerman That only made 2 lines...
You have to "close" the last line of the code. That means place the cursor behind the last line and hit [ENTER].
The SETLOCAL command limits changings of the environment to the current batch window. It's not strictly recommented but it's one of my defaults.
Regards
aGerman
Re: User Input
Posted: 20 May 2010 16:44
by 1+2=46
Why shouldn't it work?
Re: User Input
Posted: 20 May 2010 16:49
by sp11k3t3ht3rd
Well I changed around the code so I thought it might not work and aGerman whooops! sorry and thanks