I have this code:
if "%2"=="32" (
set bit=This is 32bit
)
if "%2"=="64" (
set bit=This is 64bit
)
echo %bit%
)
When I tried using sample.bat /s 64 the output is “This is 64bit”, but when I tried using sample.bat /s 32 the output is still “This is 64bit”. Then I switch it back to sample.bat 64 the ouput became “This is 32bit”. I think the variable initialization is being delayed. Does someone know a workaround?
If you run
sample.bat 64, the64is in%1, not%2. The first parameter passed to the batch file is always%1– the name of the batch file itself is in%0. You’re getting some random output remnant or something left over from another attempt. Try this:setlocalmakes sure that any environmental changes are discarded when your batch file ends, so you don’t have to worry about getting leftovers from testing.This still won’t work properly if you just type
sample.bat, because you haven’t dealt with no parameters at all being passed.