I need to know how to get and save user input in a simple batch file. I want the batch file to save the input to a text file on a computer (even if it isn't mine) and then have it sent to my email. Anyone got any idea's. Note: I am only a Junior but I have been working with batch files for about three years and I am learning to program in Java. And please no comments on programming lanuages.
This will get it into a file. To mail it you need a command line mailer. ==========================================
@echo off > newfile & setLocal enableDELAYedeXpansionset /pvar=input ?
>> newfile echo.!var!
=====================================
Life is too important to be taken seriously.M2
Thank you, but there is a problem. Every time I run the file the text file it creates only says var at the top line and that's it. Is there anyway to fix this?
You might want to also try. You can delete line 5 and 6 if you want. cls
:start
set INPUT=
set /P INPUT=Type input: %=%
echo Your input was: %INPUT%
pause
echo %INPUT% >>temp.txt
goto :start
What do you WANT in the file?
=====================================
Life is too important to be taken seriously.M2
Ok maybe I didn't explain it clear enough. I want to make a batch file that accepts input from a user. The input can be ethier numbers or letters. After the input is accepted, the batch file immediately puts whatever the user input into a text file.
M2's script will work, except the forgot a space. Try this: @echo off > newfile & setLocal enableDELAYedeXpansion set /p var=input ? >> newfile echo.!var!Like he said though, you need a command line mailer.
Can I put a question here?
Hi Matt, You're right. I left out a space after /p. Surprisingly, it works without it.
#5, That clears it right up.
=====================================
Life is too important to be taken seriously.M2
Hi M2, I was also surprised that set /pvar= works without a space after the /p, but there you are, cmd.exe can behave in strange ways. To the original poster: if your file ends up with the word var inside it, check that you have put setlocal enabledelayedexpansion at the top of your file (like M2 has). If you've left that out, that would explain why you didn't get the user input inside your file.
Hi klint, Yeah, no shortage of wackiness in CMD.
A pet annoyance is FIND for which you need spaces between each switch.
Unlike xgrep, with which I can:
xgrep -yvc "e" newfile
=====================================
Life is too important to be taken seriously.M2
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |