2011-02-23 129 views
2

我的問題與將參數傳遞給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

回答

2
@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前,然後還原值