views:

47

answers:

3

I'm trying to set up a batch file to automatically deploy a php app to a web server. Basically, what I want is an entirely automated process: I would just give it a revision number from the repository and it would then export the files, upload via ftp and then update deployment info at the repo host (codebase).

However, I'm starting from scratch here. How would I set up a batch file to accept a variable when it was run?

For example, the command myfile.bat /revision 42 should deploy revision 42 to my server.

If anyone can point me in the right direction I'd appreciate it.

+1  A: 

The % syntax refers to parameters the bat file was called with;

Create "mybat.bat" with;

echo %1 %2

then the result of the call to "mybat.bat /revision 42" is

/revision 42
RJFalconer
+2  A: 

You can pass command line parameters and get them using %1, %2, .... A nice complete article can be found here.

set var revision = %1
Beaner
A: 

to extend RJFalconer's response,%* in a batch script refers to all the arguments (e.g. %1 %2 %3 %4 %5 ...%255) (source), and a Q here on SO for how to handle trailing arguments in a lump - http://stackoverflow.com/questions/382587/how-to-get-batch-file-parameters-from-nth-position-on

matt wilkie