Forwarding all batch file parameters to inner command

17,734

Solution 1

in your batch file composer.bat, simply put:

php C:\path\to\composer\composer.phar %*

Solution 2

windows gives you %* to refer to all parameters.

Your new composer.bat file will then become
php C:\path\to\composer\composer.phar %*

Share:
17,734
Szopinski
Author by

Szopinski

Fullstack Javascript Developer @ e-point S.A.

Updated on June 20, 2022

Comments

  • Szopinski
    Szopinski almost 2 years

    For my comfort in Windows, I want to prepare some PHP tools launched like in Unix.

    f.e.: composer create-project symfony/framework-standard-edition path/

    Not: php composer.phar create-project symfony/framework-standard-edition path/

    I made composer.bat file in system path dir:

    php C:\path\to\composer\composer.phar
    

    and its works in simply usage. But how to forward all parameter and flags to command inside?

  • David A. Gray
    David A. Gray over 6 years
    I just put that together, combining a Windows NT command script (a .CMD file) with a standard desktop shortcut that has its working directory (start in) property set to the name of the project root directory. This is a real PITA for a "dynamic" scripting language, but I have a tolerable solution.
  • Eric
    Eric over 5 years
    This fails for composer.bat "^^" and swallows all the carets!
  • Justin German
    Justin German over 5 years
    That's not the case on my machine with a default command prompt. The carets get passed on to the next script.
  • Eric
    Eric over 5 years
    You're right - the problem only arises when invoked via execv or similar
  • Justin German
    Justin German over 5 years
    @Eric So this is probably more an issue of properly escaping the arguments than what this original question is about (and a downvote seems a little harsh...). But I just saw that someone pointed this already out in your question.