Click here to Skip to main content
15,899,634 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a batch script and the problem is I need the file to automatically call on and automatically input a variable

I need something like this:
<br />
::"a" Is a batch file its main contents will be after this<br />
a VAR<br />
::VAR is a the value of a variable that needs input<br />

this is a.bat:
<br />
cd Temp<br />
echo :a >> save.temp<br />
set a=<br />
set /p a=:<br />
echo :%a% >> save.temp<br />
echo echo "%a%" >> bot.temp <br />
echo goto prompt >> bot.temp<br />
cd..<br />
cd..<br />
make<br />

I want it to do the variable that needs user input, I cant just change it to something like
set a=%othervar%
because my whole program will fail.

How do I make the value go in instead of the user having to type it?
Posted
Comments
Maciej Los 15-Jul-13 17:16pm    
Why batch file?
Who wants to use it now and what's for?
G4mm4R4y 15-Jul-13 17:50pm    
What for? Its a program that makes a chatbot. Its in beta but it wont be if I can do this
Sergey Alexandrovich Kryukov 15-Jul-13 20:46pm    
Makes no sense, really. You did not really explain what you want to have (none of three of us did not really get it), but let me tell you: this is only a batch, it is not designed to do anything advanced. If a user has to type something this person has to type it, or just click some key to accept default, but not editing values or something like that.
—SA
G4mm4R4y 16-Jul-13 10:02am    
Every person has to start somewhere I started with batch. I know more advanced things, but I wanted to go back and make a simple(Or not so simple)batch file. See my commant on the answer below and see if that clarifies
Sergey Alexandrovich Kryukov 16-Jul-13 12:07pm    
If doesn't seem reasonable, and it does not properly address the simplicity issue. For example, batch is primitive, but using it is not simple.
—SA

You code has a number of bugs. Please consider this:
@echo off

define parameter=%1
echo This is first: %1
if "%parameter%"=="" set /p parameter=Enter parameter value: 

echo %parameter%

pause


Pay attention: command-line parameter is %1, not %%1; there is not "defined"; you should use string comparison, which is the operator '=='.

Does it help you?

—SA
 
Share this answer
 
Comments
G4mm4R4y 16-Jul-13 22:39pm    
Does not help, But opens ideas. Im trying to check whether or not %1 is defined if it is tthen echo it into a file (echo %1 >> file.extension)
Sergey Alexandrovich Kryukov 16-Jul-13 22:42pm    
"Does not help" and "opens ideas" are contradicting statements... :-)
—SA
Have a look here:
http://stackoverflow.com/questions/1515965/how-to-input-a-string-from-user-into-environment-variable-from-batch-file[^]
http://snipplr.com/view/14953/[^]


[EDIT #1]
If you want to call another batch file with input parameter try this:
first.bat
Delphi
second.bat "Hello world!"


second.bat
Delphi
@echo "path to me: " %0
@echo "first input variable: " %1
@echo "second input variable: " %2
rem "and so on ;)"
pause


In above example %1 variable stores text: "Helo world!"
Is that what you're looking for?

More about: Using variables in windows batch files[^]
 
Share this answer
 
v2
Comments
G4mm4R4y 15-Jul-13 17:51pm    
This is not what I meant at all. I meant a different batch file puts in the prompt for me
Maciej Los 16-Jul-13 3:02am    
See my answer now ;)
G4mm4R4y 16-Jul-13 10:01am    
This is almost what I want except I need it instead of %1 to fill out set /p a=: by itself.
G4mm4R4y 16-Jul-13 10:05am    
Ill try to make this work, but it might not.
G4mm4R4y 16-Jul-13 10:28am    
This wont work, im trying to make it condtionional. Heres the code
if defined %%1 (
echo "%1" >> bot.temp
) else (
cd Temp
echo :a >> save.temp
set a=
set /p a=:
echo :%a% >> save.temp
echo echo "%a%" >> bot.temp
echo goto prompt >> bot.temp
cd..
cd..
make
)
It wont work each time it says the variable is undefined

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900