Solved

Questions about % parameters in cmd script

Posted on 2011-09-30
3
479 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 28

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

SendBlaster Pro 4 - Bulk Email Sending Software

SendBlaster 4 Pro - Best Bulk Emailing Sending Software
Automatic Subscribe / Unsubscribe Processing
Great for Newsletters & Mass Mailings
Optional HTML & Text Composition
Integration with Google Features
Built in Spam Score Checking
Free Professional Templates - Feature Packed!

Question has a verified solution.

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

This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
Determining the an SCCM package name from the Package ID
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decadeā€¦

738 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