Solved

Questions about % parameters in cmd script

Posted on 2011-09-30
3
477 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
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 69

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…

831 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