user2715659
user2715659

Reputation: 27

How to use a .txt file as an command

I am developing on a lot of batch programs that need to have a option, to do the work easy to the user. So he can type in the host, domain, IP address name in a text file, instead of editing 10 different batch files and 1/20 lines in one batch file.

I have an idea that might work if it gets a little push:

Command.txt

ping http:www.stackoverflow.com
ping1.bat
@echo off
Cd ..
Echo testing connection.
Type command.txt {please describe the solution here}

Upvotes: 0

Views: 88

Answers (2)

M Jeremy Carter
M Jeremy Carter

Reputation: 463

It sounds like you just want a configuration file that you can reference from your batch files. I do this by setting environment variables that are defined in an .ini file.

Config.ini

host=myhostname
domain=mydomain
ip=10.10.10.1

Then in your batch files, use the command:

for /f "delims== tokens=1,*" %%A in (config.ini) do @set %%A=%%B

From that point forward, you will have 3 variables that you can use: %host%, %domain%, and %ip%.

Upvotes: 1

Endoro
Endoro

Reputation: 37569

for /f "delims=" %%a in (file.txt) do "%%~a"

Upvotes: 2

Related Questions