Solved

Passing parameters to a batch file

Posted on 2007-11-14
3
1,664 Views
Last Modified: 2008-02-01
I need to output a  log file that looks similiar to the following. JobName is a parameter that needs to be passed to the this file also. Here is the date and time code that I have so far. I just need to know how to pass the parameter of JobName.

, JobName ,20071114111658 ,

del test.log
For /f "delims=,." %%A in ("%TIME%") Do SET DATETIME=%DATE% %%A
echo , ,%date:~-4%%date:~4,2%%date:~7,2%%time:~0,2%%time:~3,2%%time:~6,2% , >> test.log


0
Comment
Question by:earngreen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Expert Comment

by:weareit
ID: 20281809
batchfilename var1 var2 var3

Would be read in the batch file as

%1 %2 and %3 respectively, i.e.:

echo Hello %1

saved as hello.bat and submitted as:

C:\>hello Paul
Hello Paul

HTH,

-saige-
0
 

Author Comment

by:earngreen
ID: 20282032
So if I need to pass multiple parameters into the batch file. It would be

echo Hello %1
echo Hello %2
echo Hello %3

I was looking at this post and it would seem to cover all the bases as long as there was at least one
parameter being passed.

http://www.experts-exchange.com/Operating_Systems/MSDOS/Q_21604344.html

Is this just overkill



0
 
LVL 12

Accepted Solution

by:
weareit earned 500 total points
ID: 20282146
You got it...  It's not really that hard, the scope of the variable remains throughout the entire batch file.

So %1 which equaled Paul in my earlier post would remain Paul until the batch file ends.

batchName.bat var1 var2 var3 var4

echo %1 %2 %3 %4
set Var1 = %1
set Var2 = %2
set Var3 = %3
set Var4 = %4
if %1 == %2 goto :end
if %3 == %4 goto :end

The above is just a short list of some of the ways an argument would be used in a batch file.

-saige-
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question