Solved

Passing parameters to a batch file

Posted on 2007-11-14
3
1,648 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
  • 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
script to remove empty folders 3 61
USB backup batch file help needed. 9 94
For loop to add numbers 3 73
Copy dir and files with robocopy 2 55
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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