Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
(This is a question about batch files)
I was wondering if there is a way to take a multi-word text variable (I'm not confused about that part) and place it in a notepad file. You know, like a survey- for example, if the program asks, "Do you like chicken? Y/N" (with the appropriate coding) and you input 'N' and the program asks you, "Why?" I would like the program to save/move the answer in a notepad file- either several answer in one notepad file, or one for every answer. Thanks in advance!

echo %var% >> some.txt
=====================================
If at first you don't succeed, you're about average.M2

Awesome! Thanks! The only problem is that if I use the program again it will remove the first variables data in that file, right? I'll try it now.

Okay, dang, it's even worse than I thought, I must be doing something wrong. I run the script:
cls
@ECHO OFF
setlocal EnableDelayedExpansion
:QUESTION
echo Do you like chicken? (Y/N)
set/p "cho=>"
if %cho%==Y goto THESTORE
if %cho%==y goto THESTORE
if %cho%==N goto SURVEY
if %cho%==n goto SURVEYecho Input unknown.
goto QUESTION:THESTORE
echo Good, I'll go buy some now.
PAUSE
goto end:SURVEY
echo What? Why don't you like chicken?
set/p !var!=Type your response:
sleep 3
echo !var!>>Reason.txtI'm probably forgetting something very simple, but I can't find out what I'm doing wrong. The program creates a new file called 'Reason' and all it says is ECHO is off.

this:
set/p !var!=Type your response:
should be:
set/p var=Type your response:
=====================================
If at first you don't succeed, you're about average.M2

Ach, thanks, I knew it was simple, works like a charm!
One final question: Say that I were to give my batch file to someone who is literally incapable of editing the code, I would want them to be able to put some data into a .txt which would then be imported to the .bat file. How would I go about importing the text? Or as a better alternative, would there be a way for the script to ask for the user to create their password on first use?

Oh, also, is there a way to make text typed into the batch file appear as asterisks (like a password)?

Not that I know of.
=====================================
If at first you don't succeed, you're about average.M2

Okay, I doubted the last (Number 7) post, but I'm still wondering at number 6, I know there's a way to call batch files and also to send text to text files, but is there a way to call text files? I really, really hope so, but if there's not, it's okay, I guess.

What does it mean to 'call a text file'?
=====================================
If at first you don't succeed, you're about average.M2

To ask for password on first run (possible that it works with XP only if you want to use %username%)
@echo off
if not exist "c:\%username%.pwd" (goto :CrePassword) else goto :login:CrePassword
cls
echo Hello: %username%
echo As this is your first time here, you need to create a password.
set /p pass1=Please enter new password:
if "%pass1%" equ "" echo You cannot make an empty password! & PAUSE & goto :CrePassword
set /p pass2=Please confirm password:
if "%pass1%" neq "%pass2%" echo Passwords doesn't match. Try again! & pause & goto :CrePassword
echo %pass1% >"c:\%username%.pwd"::Hides the file
attrib +h "c:\%username%.pwd"
:login
cls
echo LOGIN:
if exist c:\%username%.pwd set /p login=<c:\%username%.pwd
set /p pass=Enter password:
if %pass% equ %login% (goto :start) else echo Incorrect password. & pause & goto login
:Start
echo Login sucsess..
pause

![]() |
log key strokes - VB, c++...
|
Image Converter
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |