Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

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.

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=%%aThis would result in:
smtpserver=SMTPNL01.SCCT.COMPANY.COMThe 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.

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!

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 %nCAN 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.

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!

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?

![]() |
![]() |
![]() |

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