使用参数运行其他批处理文件的批处理文件

时间:2015-08-21 06:46:48

标签: windows batch-file cmd

我想要一个run.bat文件:

C:\> run functions

将运行\ exec \ functions.bat

C:\> run patches

将运行\ exec \ patches.bat

C:\> run 

将运行\exec\patches.bat\exec\functions.bat(是,按预定义顺序)

我该怎么办? Call批处理命令似乎无法正常工作

提前致谢: - )

2 个答案:

答案 0 :(得分:0)

call可以正常使用:

rem if no parameter is specified run everything
if "%1"=="" goto :run_all

rem only run the batch file that was specified
call "execs\%1.bat"
goto :eof

:run_all
  call "execs\patches.bat"
  call "execs\functions.bat"

答案 1 :(得分:0)

a_horse_with_no_name做了很多努力 - 我只是以不同的方式包装它。

@echo off
rem if no parameter is specified run everything
if "%~1"=="" (
     call "\execs\patches.bat"
     call "\execs\functions.bat"
) else (
     call "\execs\%1.bat"
)