Passing parameters from a file

May 28, 2008
5
0
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
 
May 20, 2008
603
0
Sammamish, WA
> 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.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,423
85
Albuquerque, NM
prospero.unm.edu
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.
 

samintz

Scott Mintz
May 20, 2008
1,488
15
Solon, OH, USA
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
Samintz@ra.rockwell.com
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
Thread starter Title Forum Replies Date
vefatica TCC passing expanded envvar to children? Support 3
fpefpe How to? Passing arg to gosub with white spaces Support 2
J Passing % character through command line to .btm Support 5
nickles Passing a variable to a command w/o adding it to the local environment Support 7
M Just an argument-passing "strangeness" that I didn't expect... Support 19
M Backquoted parameters used in GoSub don't pass string as a single parameter Support 2
vefatica Quoting @Function parameters? Support 0
vefatica Batch parameters broken? Support 2
D Arithmatic on a sub's parameters Support 4
T Fixed Problem with use of Batch parameters in the IDE Support 1
D Documentation Modifying GOSUB parameters Support 10
H UNIQUE[] without parameters gives error Support 1
vefatica Aliases ... appending unused parameters? Support 2
Jay Sage WAD Possible Bug in Batch Parameters Support 7
E Parameters dialog box problem Support 2
Rich Skorski effect of CMDVariables on parameters Support 3
D Clear alias parameters Support 7
Mordachai Help! How to set parameters for script I'm debugging?! Support 6
S Documentation Topic: Batch File Parameters Support 14
R command line parameters / file associations Support 4
Y TC Tab parameters Support 2
JohnQSmith New online help file wrong logo Support 7
Jay Sage WAD Possible Bug With OPTION Command With @FILE Support 5
samintz How to? swap endianness in a binary file Support 12
vefatica `Back quotes` - command line vs. batch file Support 5
fpefpe How to? batch file size Support 2
Jay Sage Issues With TCMD File Explorer Support 0
FreezerBurnt Help making a CMD and TCC compatible batch file Support 7
Joe Caverly @FILESIZE and NTFS File Stream Support 1
Joe Caverly Embedding an .EXE (or other file) into a .BTM Support 8
U Command help on file names Support 5
S Concatenate all playlists into 1 file Support 22
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
Joe Caverly Rename file that begins with Emoji Support 7
Joe Caverly PSHELL and NTFS File Streams Support 2
P Kill all other instances of tcc from a btm batch file Support 2
D ffind hangs on large file Support 18
Alpengreis Documentation Minor issue in help file for view /E Support 1
fpefpe batch file ending early Support 18
J Licesne file location Support 1
K robocopy cancelling batch file processing Support 28
Jay Sage TCMD Crashes with "tctoolbar /c /r file" Support 5
A Unable to pass batch file arguments unaltered Support 18
MikeBaas How to...extract a string from a .json-file? Support 10
vefatica LIBRARY and file name completion? Support 4
D What does the file "..\Everything\Run history.csv" store? Support 5
H Takecommand.pdf failed not a pdf file Support 6
Joe Caverly DIRectory Colorization in v25 Help File Support 0
C show file description? with dir? Support 8
D When copying/moving, appending " (2)" to filename when the target file already exist. Support 7

Similar threads