Solved

Questions about % parameters in cmd script

Posted on 2011-09-30
3
480 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
[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
3 Comments
 
LVL 1

Assisted Solution

by:d33m
d33m earned 150 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 150 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 70

Accepted Solution

by:
Qlemo earned 200 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
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…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

631 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