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

Batch file 在bat中运行多个bat文件并传递参数,batch-file,Batch File,我的问题与将参数传递给bat文件有关。第一个参数正确地传递给bat,但第二次传递参数时,它是emtpy 例如: 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之后,如

我的问题与将参数传递给bat文件有关。第一个参数正确地传递给bat,但第二次传递参数时,它是emtpy

例如:

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之后,如何使“main”bat级别上的call参数保留在内存中

@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,然后恢复值

@Tomas:我必须说,我看不出
%comport%
如何计算为
com4
。它当然不能用
set
命令初始化,
=
被空格包围。是的,正确。我应该写出来这只是伪代码。这更像是我想要的一般解决方案。调用第一个bat后comport为空。@Tomas:我想你肯定知道
bat1.bat
不可能重置变量,不是吗。真的是这样吗?Bat1.bat位于我的项目的另一部分,无法修改,并且在内部使用相同的变量名%comport%,在某些情况下将其设置为“”。确实,这似乎清除了我的文件中使用的变量。@Tomas:正如预期的那样。如果可以,选择一个不同的名称(当然,在其他批处理文件中不使用),问题就会消失。