Solved

Passing parameters to a batch file

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now