Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forwarding all batch file parameters to inner command

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?

like image 998
Szopinski Avatar asked Jul 24 '12 18:07

Szopinski


People also ask

How do I pass arguments from one batch file to another?

You can pass in the batch1. bat variables as arguments to batch2. bat. @echo off cls set file_var1=world set file_var2=%computername% call arg_batch2.

What does %% do in batch file?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

What is %% g'in batch file?

%%parameter : A replaceable parameter: in a batch file use %%G (on the command line %G) FOR /F processing of a command consists of reading the output from the command one line at a time and then breaking the line up into individual items of data or 'tokens'.

How do you redirect the output of a command to a file in batch?

Use >filename. txt 2>&1 to merge Standard Output and Standard Error and redirect them together to a single file. Make sure you place the redirection "commands" in this order.


2 Answers

in your batch file composer.bat, simply put:

php C:\path\to\composer\composer.phar %* 
like image 76
marapet Avatar answered Sep 19 '22 16:09

marapet


windows gives you %* to refer to all parameters.

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

like image 32
SeanC Avatar answered Sep 18 '22 16:09

SeanC