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

x
?
Solved

Questions about % parameters in cmd script

Posted on 2011-09-30
3
Medium Priority
?
483 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 600 total points
ID: 36891942
answering to your first question:
I hope this can help you
for %%x in (%*) do ...
0
 
LVL 29

Assisted Solution

by:Michael Pfister
Michael Pfister earned 600 total points
ID: 36891971
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 71

Accepted Solution

by:
Qlemo earned 800 total points
ID: 36892211
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
It is a real story and is one of my scariest tech experiences. Most users think that IT experts like us know how to fix all computer problems. However, if there is a time constraint and you MUST not fail the task or you will lose your job, a simple …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

783 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