[comp.os.msdos.programmer] Passing command line arguments from .bat file to application?

brand@janus.Berkeley.EDU (Graham Brand) (10/11/90)

I have been trying, without success, to pass a batch file command
line argument to a program that is invoked from inside the batch
file. The batch file has something like:
	.....
	programname "%1"
	.....
and is invoked as:
	batchfilename param

but programname never gets param. Would someone advise me how to do 
this correctly? 

Cheers,
-Graham

ts@uwasa.fi (Timo Salmi) (10/11/90)

In article <39104@ucbvax.BERKELEY.EDU> brand@janus.Berkeley.EDU writes:
>I have been trying, without success, to pass a batch file command
>line argument to a program that is invoked from inside the batch
>file. The batch file has something like:
>	.....
>	programname "%1"
                       ^ simple, don't use the quotes

...................................................................
Prof. Timo Salmi        (Moderating at anon. ftp site 128.214.12.3)
School of Business Studies, University of Vaasa, SF-65101, Finland
Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun

msmith%albion.utah.edu@cs.utah.edu (Matthew Smith) (10/12/90)

In article <39104@ucbvax.BERKELEY.EDU> brand@janus.Berkeley.EDU writes:
>I have been trying, without success, to pass a batch file command
>line argument to a program that is invoked from inside the batch
>file. The batch file has something like:
>	.....
>	programname "%1"
>	.....
>and is invoked as:
>	batchfilename param
>
>but programname never gets param. Would someone advise me how to do 
>this correctly? 

Well, I'm not sure if you put those ""'s around the %1 in your batch file
or not, if you did, you shouldn't.  If I called a batch file called BATCH
with the parameters A B C D, like such:  BATCH A B C D 
then, inside the batch file, any reference made to %1 would be replaced 
by A, %2 by B, etc...
 
So, if in the batch file, I wanted to call MYPROG with the first parameter
passed to BATCH, my batch file would look like this:

MYPROG %1

I think you had the right idea, depending on if you put those quotes there
or not...


>Cheers,
>-Graham

(*SWIG*) (*ahhh*)
thanks!
 
Matt Smith

msmith@peruvian.utah.edu

roy%cybrspc@cs.umn.edu (Roy M. Silvernail) (10/12/90)

brand@janus.Berkeley.EDU (Graham Brand) writes:

> I have been trying, without success, to pass a batch file command
> line argument to a program that is invoked from inside the batch
> file. The batch file has something like:
> 	.....
> 	programname "%1"
> 	.....
> and is invoked as:
> 	batchfilename param
> 
> but programname never gets param. Would someone advise me how to do 
> this correctly? 

The quotes are the problem. If you use simply

        progname %1

and invoke as

        batfile param

progname will get param passed as you wish. For even more control in
batch files, look into 4dos. The batch support is phenominal!
--
Roy M. Silvernail |+|  roy%cybrspc@cs.umn.edu  |+| #define opinions ALL_MINE;
main(){float x=1;x=x/50;printf("It's only $%.2f, but it's my $%.2f!\n",x,x);}
"This is cyberspace." -- Peter da Silva  :--:  "...and I like it here!" -- me