有效地将多个交换机传递给批处理文件?

时间:2013-06-26 01:05:03

标签: windows batch-file

以这种格式将多个命令行参数传递给批处理文件的最有效方法是什么?

PACKER.BAT /Action="Pack" /Source="..\path to source folder\" /Target="..\path to target folder\" /Pass="SecretCode" /Output="Packed.exe" /GPGhome="..\path to GnuPG home directory\" /User="UserID" /Admin="AdminID" /Profile="ProfileID"

在.BAT中,我想将开关的前导“/”和“SET”作为环境变量去除。

变量将传递给7Zip,GPG,DWipe和一些基本的错误检查。适用于Vista,Win7和Win8。

PACKER.BAT笔记和片段......

:Start
:: Prepare the Command Processor & initialise variables
Set colours, title, comments, errorlevels, etc.
Read variables from general profile file, etc.
Process command line arguments

:Lock
if exist %Lock% @echo ž   WARNING:  %ProfileID%  is running.

:Check
if exist %Action%="Pack" do ... else UnPack, etc.
if exist %Source% do ... else error
if exist %Target% do ... else create

:Zip
%7Zexe% u -ms=off -mtc=on -ssw -w%Temp% -p%Pass% -mhe=on %sfx:"=% %Target%%Output% %Source%

:GPG
%GPGexe% --homedir %GPGhome% -r %UserID% -r %AdminID% -e %Target%%Output%

:Wipe
%DWexe% wipe1 %Target%%Output%

:Help
@echo Allowable switches for %ProfileID%:
@echo %Menu:"=%

:End
:: clean up environment variables

¯¯¯¯

1 个答案:

答案 0 :(得分:3)

@echo off

rem Erase all existent variables to show the created ones at end
setlocal EnableDelayedExpansion
for /F "delims==" %%a in ('set') do set %%a=

rem Get the parameters and define variables with them
set var=
for %%a in (%*) do (
   if not defined var (
      set var=%%a
   ) else (
      set !var:~1!=%%~a
      set var=
   )
)

rem Show all defined variables
set

例如,如果执行:

  

PACKER.BAT / Action =“Pack”/Source=".​​.\path到源文件夹\“/ Target="..\path到    目标文件夹\“/ Pass =”SecretCode“/Output="Packed.exe”/GPGhome="..\path to Gn   uPG主目录\“/ User =”UserID“/ Admin =”AdminID“/ Profile =”ProfileID“

输出是:

Action=Pack
Admin=AdminID
GPGhome=..\path to GnuPG home directory\
Output=Packed.exe
Pass=SecretCode
Profile=ProfileID
Source=..\path to source folder\
Target=..\path to target folder\
User=UserID