Weird Batch File Issue

Can someone help me with this one? I have a batch file, where I am trying to connect a couple network drives based on my current internal IP address. Problem is, it is outputting the following:

Home Basement

Where it should be just outputting: Home

Here's the code:

@echo off

@for /F "tokens=2 delims=:" %%i in ('"ipconfig | findstr IP | findstr 192."') do SET LOCAL_IP=%%i

@if ("%LOCAL_IP%" == "") Call ConnectHome else (Call ConnectBasement)

@echo Home %LOCAL_IP%

@echo Basement
@REM net use R: \\\Storage
@REM net use S: \\\MyStuff
@REM net use T: \\\Server

I've also tried replacing the IF statement with:

@if ("%LOCAL_IP%" == "") goto ConnectHome else (goto ConnectBasement)


@if ("%LOCAL_IP%" == "") goto :ConnectHome else (goto :ConnectBasement)

and the results are always the same... OS is Windows 7 Pro


Call is intended to call a different batch file from the one you're currently in (see here). If it's passed a label, it will execute from that label, but it'll execute to the end of the file, so it won't stop when it hits the :ConnectBasement line.

What you probably need is to add a label :END at the bottom of the file, and Goto :END just before your :ConnectBasement line. For consistency I'd probably suggest using Goto instead of Call throughout. (You can also use Goto :EOF without defining a label, if you wish.)

(Or, learn PowerShell and use its functioning capability to implement this more cleanly ;-))

After going to :ConnectHome, it just goes to :ConnectBasement. Add goto :eof just below @echo Home %LOCAL_IP%.

Aren't you forgetting to stop execution after the :ConnectHome part ? I'm not sure, but I think the batch simply continues after that, printing "Basement".

edit: Jeroen beat me to it :)

Need Your Help

Records not being saved to core data sqlite file

database sqlite core-data ios5 import

I'm a complete newbie when it comes to iOS programming and much less Core Data. It's rather non-intuitive for me, as I really came into my own with programming with MATLAB, which I guess is more o...

JsonMappingException: No suitable constructor found for type FacebookProfile

java facebook json integration spring-social

I connect to facebook using OAuth2.0 protocol. And everything is allright cause i get access_token on the server now i want to connect to facebook and get it API. but i recieve JSON exception. so t...