在bat中运行多个bat文件并传递参数

在bat中运行多个bat文件并传递参数

问题描述:

我的问题与将参数传递给bat文件有关。第一个参数正确传递给bat,但第二次参数传递给它。在bat中运行多个bat文件并传递参数

实施例:

set comport = com4 
call bat1.bat %comport%  ->comport is com4 
if errorlevel 1 goto end 
call bat2.bat %comport%  ->comport is empty 

所以后bat1.bat COMPORT的第一呼叫是空的。在bat1.bat的调用之后,如何让“主”蝙蝠级别的调用参数保留在内存中?

+0

@托马斯:我必须说,我看不到'%comport%'如何能够首先评估为'com4'。它肯定不能由'set'命令初始化,其中'='被空格包围。 – 2011-02-23 18:25:48

+0

是的,的确如此。我应该写出它只是伪代码。这是我追求的一般解决方案。调用第一只蝙蝠后,comport是空的。 – Tomas 2011-02-23 19:33:15

+0

@Tomas:我想你肯定知道'bat1.bat'不能重置变量,不是吗。 – 2011-02-23 19:42:44

@echo off 
set comport=com4 
setlocal&(call bat1.bat %comport%)&endlocal 
if errorlevel 1 goto end 
call bat2.bat %comport% 
:end 

SETLOCAL只能在WinNT4 +,而不是DOS或Win9x的,如果您需要支持那些你必须%COMPORT%保存到其他一些变量调用bat1.bat前,然后还原值