1.

Solve : Resolving Parameters in a Batch program?

Answer»

I've been using batch programs for ages, but I'm in a situation here where I would like to not run the program from a command prompt in XP, but while the batch is running, allow the user to enter the parameters to be resolved as the %1, %2, etc. that would normally be entered after the myjob.bat.

myjob 12345 ADB Counts CustomerName

I USED a program once that would basically bring up a SCREEN allowing you to enter fields and when pressing the appropriate "F" key, the program would resolve the parameters into the batch file and run the program.

I can't remember the program that was, but is there a way to do this in a Batch or do I need to look at a VB script program instead?

I'm trying to keep it simple.You can write a batch script which gathers user input and then passes it to another batch file or indeed to a program

The set command with the /p switch allows you to ask the user to input a string

like so

Quote

@echo off
Set /P param1=Please input parameter 1 %
Set /P param2=Please input parameter 2 %
Set /P param3=Please input parameter 3 %
Set /P param4=Please input parameter 4 %
myjob %param1% %param2% %param3% %param4%

set /p syntax...

set /p variablename=prompt string for user [%]

The % SIGN is optional; I use it so there is a space between the end of the prompt string and the flashing cursor at which the user input will be typed. If you omit it, the user input follows immediately after the last non-space character of the prompt string, i.e. trailing spaces in the prompt string are ignored. The prompt string is not compulsory...

set /p dummy=

will wait for a string (i.e. zero or more chars plus ENTER) which might be handier SOMETIMES than PAUSE.





That looks like it will WORK, one question though....on the "myjob %param1%....Does that need to be a CALL statement infront or no?

I'm used to making a call to another .bat file start with CALL.

Thank you,Oh right. I wasn't sure if myjob was a bat or an exe. Anyway, you generally use CALL in a batch file when you want to transfer execution to another batch file and then return when that second batch file is complete.

this is batch1.bat:-

@echo off
(some code)
call batch2.bat %param1% %param2% etc
(some more code)

(some more code) gets executed when (and if) batch2.bat finishes.

This is batchA.bat

@echo off
(some code)
batchB.bat %param1% %param2% etc
(some more code)

batchB.bat starts and runs but (some more code) will never be executed if or when batchB.bat finished because control has passed completely to batchB.bat.

For executables (.exe) the situation is that if you just place the executable name in a line, the batch file and hence the command window will wait for it to complete, then executing any lines following.

@echo off
(some code)
program.exe %param1% %param2%
(some more code)

above, (some more code) gets executed after program.exe finishes.

If you want the batch to start the exe and then quit without waiting, you use the START command thus

@echo off
(some code)
start "" "program.exe" %param1% %param2%
(some more code)

in this one, the program is started and then (some more code) - if present - is executed at once, and the batch will quit if there is no more code.











alright, thanks...I'm deep into the batch now and the preliminary testing has been favorable.

Thanks for your help!


Discussion

No Comment Found