Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Passing parameters to a batch file

Posted on 2007-11-14
3
Medium Priority
?
1,677 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 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

660 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