Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOS commands

Status
Not open for further replies.

Cretin

Technical User
Jan 2, 2003
194
US
I was not sure where to put this so here it goes.

I have been given the task of creating a .bat file using DOS commands that depending on the parameter sent would take some action. My question is there may be up to 25 or 30 different parameters the .bat file may receive and have to recognize. What would the best way to do that be? A 25 line nested if statement could get quite complicated.




Cretin
 
Can you use vbscript or javascript as a .wsf file?


Have a look at

In particular named and unnamed. They allow you to create both positional and named parameters: as many as you wish. Also, it will automatically generate the help text telling you what the parameters are if you get them wrong.

The other alternative is Powershell but I don't know a lot about that.
 
For such a complex bat file, I wonder if using VB may not be a better alternative.

Anyway, you can fake a switch statement using a GOTO call.
Assuming the bat file will only ever take one parameter when its called, you can do something like:
Code:
GOTO CASE_[red]%1[/red]
:CASE_ALPHA
    ECHO The parameter was Alpha
    GOTO END_SWITCH
:CASE_BETA
    ECHO The parameter was Beta
    GOTO END_SWITCH
:CASE_GAMMA
    ECHO The parameter was Gamma
    GOTO END_SWITCH

:END_SWITCH

Note that you'll get an error if the parameter doesn't exactly match any of the cases.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
The other trick fake thing that you often see is
Code:
CALL :CASE_%1
....
EXIT

:CASE_ALPHA
   ECHO sub alpha
   GOTO :EOF

:CASE_BRAVO
   ECHO sub bravo
   GOTO :EOF

:CASE_CHARLIE
   ECHO sub charlie
   GOTO :EOF
I find it slightly easier to read as the main logic is not broken up by huge case statements.
 
I would prefer to use VB but they may not let me however we may do a different tack.

We have a scheduler that can submit jobs based on file notification(based on name of file).

When an Oracle job runs through Grid control it can pass a parameter to a .bat such as the name of a job. The .bat file could rename a .txt file to something and when that happens the enterprise scheduler releases a job based on that file.

Example: A job called myjob runs on the oracle scheduler. It passes the parameter myjob to a .bat job. On that drive sits a text file called do.txt. Once the parameter myjob is passed to the .bat file it copies and renames do.txt to myjob.txt. Once myjob.txt is on the drive the enterprise scheduler sees it and rleases the job that is set to release when myjob.txt is there. Now is all I need to do is figure out how to do that *L*

Cretin
 
I did figure it out thanks for all your help.

Cretin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top