Computing.Net > Forums > Disk Operating System > Batchfile to read configfile

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batchfile to read configfile

Reply to Message Icon

Name: ikerstges
Date: March 30, 2004 at 02:38:46 Pacific
OS: Win95 DOS
CPU/Ram: PII/128
Comment:

Hi all,

I want to use a kind of configuration file for my batch scripts (like 'settings.ini' or 'settings.cfg'). In this file I would like to centralise certain settings like servernames for specific commands. This would then allow me to switch all scripts from one server to a backup server by editing the 'cfg' or 'ini' file....

How can I
a) Read a text file
b) Store line 1 into variable %a
AND
c) Store line 2 into variable %b
OR
d) Store line n into variable %n

???

Hope this can be done in DOS!?

Kind regards,
Igor.



Sponsored Link
Ads by Google

Response Number 1
Name: wizard-fred
Date: March 30, 2004 at 07:12:41 Pacific
Reply:

Why not have an IF in the batch.

IF %1 = server1 then branch to task1
IF %1 = server2 then branch to task2
...

You won't need a separate confiuration file. You can also add more parameters as needed.


0

Response Number 2
Name: ikerstges
Date: March 30, 2004 at 07:51:01 Pacific
Reply:

Hi,

I run these jobs in a scheduler, preferably unattended.... These batch-files run ftp-uploads and ftp-downloads, smtp-send mail and more jobs of such kind.

I would like to have a centralised approach where I can switch to a backup servername if the mainserver fails by entering a new name in the corresponding line.

I think that a solution in w2k command environment will be possible with use of command "for", but that's also too difficult to me. I can only read 1 line of such file into a variable

filename: c:\settings\config.cfg
line 1: SMTPNL01.SCCT.COMPANY.COM;

batch line:
FOR /F "tokens=1 delims=;" %%a in ('type c:\settings\config.cfg') do set smtpserver=%%a

This would result in:
smtpserver=SMTPNL01.SCCT.COMPANY.COM

The disadvantage is that this only allows a single line in config.cfg while I would like to direct the contents of line 1 into variable smtpserver and/or direct the contents of line 2 into variable ftpserver etc. etc.......

Any help will be greatly appreciated!

(sorry, maybe I'm getting a bit off-topic here, but I'm quite desperate to have a solution since I'm editing loads of scripts when we have a fail-over!!)

Have a nice day!
Igor.


0

Response Number 3
Name: Wengier
Date: March 30, 2004 at 09:40:42 Pacific
Reply:

Hi ikerstges,

"I run these jobs in a scheduler, preferably unattended.... These batch-files run ftp-uploads and ftp-downloads, smtp-send mail and more jobs of such kind."

"I think that a solution in w2k command environment will be possible with use of command "for", but that's also too difficult to me."

"FOR /F "tokens=1 delims=;" %%a in ('type c:\settings\config.cfg') do set smtpserver=%%a

Have you noticed that this is a NT batch command, not a DOS batch command at all? What's the exact OS are you using? DOS+Win95 (as you said in your OS column) or Windows 2000 (as you mentioned in your message body)? Very confusing, isn't it? I know your last post in this forum was removed because it was off-topic. If you really want to have a solution as quickly as possible, then you should try the correct forum rather than the unrelated forum. For example, If your OS is NT system (WinNT/2K/XP) instead of DOS, then you'd better post it in the corresponding forum. Note that you cannot run "NT schedualer, ftp-uploads and ftp-downloads, smtp-send mail and more jobs" or NT batch scripts from DOS!

More information:

http://computing.net/dos/wwwboard/forum/14722.html

---------------
Long Live DOS!


0

Response Number 4
Name: ikerstges
Date: April 1, 2004 at 01:32:44 Pacific
Reply:

Hi Wengier,

I understand your concerns and indeed, this topic should stay on DOS. Maybe I added to some confusing with my reference to the "FOR" solution, but it was only to explain what kind of solution I Am looking for.

Let me repeat: I would like to have a Win95/DOS solution that allows me to:
a) Read a text file
b) Store line 1 into variable %a
AND
c) Store line 2 into variable %b
OR
d) Store line n into variable %n

CAN THIS BE DONE IN WIN95/DOS?

Let me assure you that I have almost 100 hourly and/or daily and/or weekly jobs running on this environment to send emails (using blat) and running FTP-transfers!!!

Kind regards,
Igor.

ps: My other request was related to use nslookup for my smpt-server name(s) and that was indeed w2k command. I apologised for posting that request in the wrong forum. My apologise was truely and sincerely.


0

Response Number 5
Name: Wengier
Date: April 1, 2004 at 12:50:17 Pacific
Reply:

That's OK.

For a DOS solution on a DOS system (DOS/Win3.x/9x), you can try the methods suggested in #25 on this page:

http://www.batch.hpg.ig.com.br/

Alternatively, a simpler way is to use some additional batch tools, such as STRINGS.

Good luck.

---------------
Long Live DOS!


0

Related Posts

See More



Response Number 6
Name: ikerstges
Date: April 2, 2004 at 02:22:38 Pacific
Reply:

I have checked solution #25 AND #24. These are great, especially #24 is related to my question.

I cannot find though, how to direct the program to a SPECIFIC line in the file and store the content of that line into my variable.... I would somehow need to tell the program to process i.e. line 3 of my configfile and store the content of that line into a variablename.

Any help please?


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batchfile to read configfile

Force WinME to read autoexec.bat. www.computing.net/answers/dos/force-winme-to-read-autoexecbat/14202.html

batchfile to copy files with datename www.computing.net/answers/dos/batchfile-to-copy-files-with-datename/10842.html

dos command to read txt /p www.computing.net/answers/dos/dos-command-to-read-txt-p/8632.html