4

I use batch files to create wrappers around some commands which need extra argument to work. For example, I have a file pip.cmd which adds a custom proxy argument to all pip calls:

pip.exe --proxy="myproxy" %1 %2 %3 %4 %5

As you can see, I'm using %1 notation to transfer arguments of pip.cmd to pip.exe, however, my approach breaks if there's more than 5 arguments. In Linux, I'd simply use "$@", which handles all the arguments at once. Is there a similar notation or a reasonable workaround for a Windows shell?

3
  • You can merge several parameters to one by quoting them like "par1 par2 ... parN" Commented Jan 28, 2016 at 14:11
  • @duDE I don't want to merge arguments. I want pip.cmd arg1 arg2 argN become pip.exe --proxy="myproxy" arg1 arg2 argN for any N. Commented Jan 28, 2016 at 14:13
  • @duDE YHO is wrong ;)
    – DavidPostill
    Commented Jan 28, 2016 at 14:21

2 Answers 2

10

Is there a similar notation or a reasonable workaround for a Windows shell?

%* is the cmd equivalent of $@ in Unix.

Note:

  • A maximum of 255 parameters is allowed.

Example (pip.cmd):

pip.exe --proxy="myproxy" %*

Command Line arguments (Parameters)

%* in a batch script refers to all the arguments (e.g. %1 %2 %3 %4 %5 ...%255)

Source - parameters


Further Reading

3

You can use %*:

@echo off
echo %0
echo %*

Running this will give:

C:\>test.cmd this is a test 1 2  3  4  5 6 7 8
test.cmd
this is a test 1 2  3  4  5 6 7 8

Where %0 is the command/program name, and %* all the parameters.

See this article.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .