46

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?

Szopinski
  • 790
  • 1
  • 10
  • 18

2 Answers2

76

in your batch file composer.bat, simply put:

php C:\path\to\composer\composer.phar %*
marapet
  • 54,856
  • 12
  • 170
  • 184
  • 1
    This fails for `composer.bat "^^"` and swallows all the carets! – Eric Aug 09 '18 at 01:26
  • That's not the case on my machine with a default command prompt. The carets get passed on to the next script. – marapet Aug 09 '18 at 08:00
  • You're right - the problem only arises when invoked via `execv` or similar – Eric Aug 09 '18 at 09:23
  • @Eric So this is probably more an issue of properly [escaping the arguments](https://ss64.com/nt/syntax-esc.html) 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. – marapet Aug 09 '18 at 11:52
22

windows gives you %* to refer to all parameters.

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

SeanC
  • 15,695
  • 5
  • 45
  • 66
  • 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. – David A. Gray Oct 19 '17 at 22:59