Solved

Questions about % parameters in cmd script

Posted on 2011-09-30
3
475 Views
Last Modified: 2012-05-12
1. How do I refer in a script to "all" parameters, instead of coding %1 %2 %3 ....
2. How can I pass a equal sign to a script, as it seems to disappear when passed to it
0
Comment
Question by:LeTay
3 Comments
 
LVL 1

Assisted Solution

by:d33m
d33m earned 150 total points
Comment Utility
answering to your first question:
I hope this can help you
for %%x in (%*) do ...
0
 
LVL 28

Assisted Solution

by:Michael Pfister
Michael Pfister earned 150 total points
Comment Utility
1. %*
i.e.
echo %*

2. If you use %1, %2 etc., the = is recognized as a seperator between the paramters, so calling a batch like

Test.cmd PARAM=1 PARAM2
would result in

%1 = PARAM
%2 = 1
%3 = PARAM2

Using %* will return the entire line including the =
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 200 total points
Comment Utility
Regarding the equal sign: It is treated as a special character, like semicolon and comma. All those are taken as parameter separators. You can not override that behaviour from inside the batch file.
Either you:
* use %*, and parse the contents yourself,
* or need to enclose the parameter pair into double quotes:
          test.cmd "param1=1"
* or use paired vars
          test.cmd param1=1
  and in the batch:
          @echo %1=%2 %3=%4
  resp., more automated:
          set parm=%1&& shift && set val=%2 && shift
          @echo %parm% = %val%
          set parm=%1&& shift && set val=%2 && shift
          @echo %parm% = %val%

0

Featured Post

Don't lose your head updating email signatures!

Do your end users still have the wrong email signature? Do email signature updates bore you or fill you with a sense of dread? You can make this a whole lot easier on yourself by trusting an Exclaimer email signature management solution. Over 50 million users do...so should you!

Join & Write a Comment

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

728 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

9 Experts available now in Live!

Get 1:1 Help Now