how to save user input in batch file

December 17, 2010 at 09:13:15
Specs: Windows XP/Vista
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.

See More: how to save user input in batch file

Report •

#1
December 17, 2010 at 12:28:39
This will get it into a file. To mail it you need a command line mailer.

==========================================
@echo off > newfile & setLocal enableDELAYedeXpansion

set /pvar=input ?
>> newfile echo.!var!


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
December 17, 2010 at 15:21:40
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?

Report •

#3
December 17, 2010 at 21:32:59
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


Report •

Related Solutions

#4
December 18, 2010 at 01:42:41
What do you WANT in the file?


=====================================
Life is too important to be taken seriously.

M2


Report •

#5
December 18, 2010 at 09:27:42
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.

Report •

#6
December 18, 2010 at 14:32:18
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?


Report •

#7
December 19, 2010 at 00:49:23
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


Report •

#8
December 19, 2010 at 07:22:29
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.

Report •

#9
December 20, 2010 at 01:51:37
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


Report •

Ask Question