Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Passing parameters from a file

I want to use a file or files to pass parameters to a batch file where I'd use it as a %var%. I want to avoid human involvement and get all the parameters required from a text file or other batch file residing in the same directory.

Is there a way to have a batch file read another batch file to get a variable/parameter?

In other words batchA.cmd says call batchB.cmd

BatchB contains only a string such as "45553442" or "MCCNumericCode"

BatchA then uses that variable (%whatever%) in its execution.

Doable?

Mike Nelson
 
> BatchB contains only a string such as "45553442" or "MCCNumericCode"
> BatchA then uses that variable (%whatever%) in its execution.

You bet. Here's one way using the @line[] function:
TCC 9.02.148 Windows XP [Version 5.1.2600]
TCC Build 148 Windows XP Build 2600 Service Pack 3


D:\>type datafile.dat
45553442
MCCNumericCode

D:\>type batcha.btm
@echo off
set whatever=%@line[datafile.dat,0]
echo I read %whatever% from the first entry of data file

set whatever=%@line[datafile.dat,1]
echo I read %whatever% from the second entry of data file

D:\>batcha.btm
I read 45553442 from the first entry of data file
I read MCCNumericCode from the second entry of data file


--
2008 Fridays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Saturday.
Measure wealth by the things you have for which you would not take money.
 
therealmikenelson wrote:
| I want to use a file or files to pass parameters to a batch file
| where I'd use it as a %var%. I want to avoid human involvement and
| get all the parameters required from a text file or other batch file
| residing in the same directory.
|
| Is there a way to have a batch file read another batch file to get a
| variable/parameter?
|
| In other words batchA.cmd says call batchB.cmd
|
| BatchB contains only a string such as "45553442" or "MCCNumericCode"
|
| BatchA then uses that variable (%whatever%) in its execution.
|
| Doable?

Yes. Look at the @line[] function. Excellent if file has only a few lines.
You can also do this:

set n=0
do val in @batchb.cmd
set var%n=%val
set n=%@inc[%n]
enddo


This will set var0 to the contents of line 0, var1 to the contents of line
1, etc.

Another technique is to format the data file in the style of .INI files,
with sections and variables with values. You can read the values using
@iniread[].

BTW, .CMD for data files is not a good extension - it is misleading, one
expects a script file designed for CMD.EXE.

Furthermore, .BTM files are executed faster in TCC than .CMD files.
--
HTH, Steve
 
therealmikenelson wrote:
BTW, .CMD for data files is not a good extension - it is misleading, one
expects a script file designed for CMD.EXE.

Furthermore, .BTM files are executed faster in TCC than .CMD files.

Actually, since the second file isn't a batch file at all (it doesn't contain commands), I would suggest a .TXT extension.
 
You have a number of options to achieve that goal. The simplest is to
have two script files and just have the first call the second passing the
second the parms it needs.

batchA:
call batchB parm1 parm2 parm3

batchB:
echo %1 %2 %3


A second option would allow you to use a response file:

rspfile:
parm1
parm2
parm3

batchA:
echo %@line[rspfile,0] %@line[rspfile,1] %@line[rspfile,2]

You could also have all 3 parms on the same line and pick out the
individual parameters using @WORD or @FIELD

And you could also use an INI file and use @INIREAD to pull out the named
items you want.

There are additional ways to achieve this goal as well. But that should
be enough to get you started.

-Scott




therealmikenelson <>
05/31/2008 01:39 PM
Please respond to



To
[email protected]
cc

Subject
[Support-t-97] Passing parameters from a file






I want to use a file or files to pass parameters to a batch file where I'd
use it as a %var%. I want to avoid human involvement and get all the
parameters required from a text file or other batch file residing in the
same directory.

Is there a way to have a batch file read another batch file to get a
variable/parameter?

In other words batchA.cmd says call batchB.cmd

BatchB contains only a string such as "45553442" or "MCCNumericCode"

BatchA then uses that variable (%whatever%) in its execution.

Doable?

Mike Nelson
 

Similar threads

Back
Top