Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run one exe by passing dynamic parameters using single bat file

Tags:

batch-file

I have an requirement to run one EXE. It will take 7 parameters out of which one parameter is dynamic. Could some one help me how to run the EXE by passing dynamic parameters using bat file.

Thanks Chaitanya

like image 545
Chaitanya Avatar asked May 26 '11 16:05

Chaitanya


2 Answers

If you need to execute a command with a dynamic number of parameters you can use %*.

Example Command:

foo.exe [options] <file1> <file2> ...

Say you wanted to have a batch script which sets some options but still passes a dynamic number of files

foo.bat

@ECHO OFF;
foo.exe -some -option %*

Running:

foo.bat file1.txt file2.txt

Translates To:

foo.exe -some -option file1.txt file2.txt
like image 109
Ilia Choly Avatar answered Oct 08 '22 23:10

Ilia Choly


If you want to run this :

my_7_param_program.exe p1 p2 p3 p4 p5 p6 p7

With, say, p4 as a dynamic parameter, try this batch file:

@my_7_param_program.exe p1 p2 p3 %1 p5 p6 p7

and call it like this :

c:\> my_batch.bat 42

So the actual call will be

my_7_param_program.exe p1 p2 p3 42 p5 p6 p7

With the p1, p2, p3, p5, p6 and p7 hardcoded parameters.

like image 36
ixe013 Avatar answered Oct 09 '22 00:10

ixe013