Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1692
  • Last Modified:

Passing parameters to a batch file

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
earngreen
Asked:
earngreen
  • 2
1 Solution
 
weareitCommented:
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
 
earngreenAuthor Commented:
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
 
weareitCommented:
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now