variables - MS DOS IF and % percent -


i haven't done dos in forever , can't recall idiosyncracies prefixing labels %. i'm trying write script (others may find useful) connect adb wifi service running on tablet.

@echo off set def=192.168.1.21 if "%1" == "" (     echo.please supply ip address of adb server/tablet.     set /p ip=[%def%]     if %ip% == "" (       set ip=%def%     ) ) else (     set ip=%1     "c:\program files\adt-bundle-windows-x86_64-20130219\sdk\platform-tools\adb" connect "%ip":5555 ) 

the script should accept ip address on commandline, if none supplied, if should prompt operator. if nothing entered, printed, square bracketed default should used.

it seems work, except that

set ip=%def% 

never executes. think messed second if statement. can't % signs in right place!! remember old black magic?

thanks.

no need set ip default if user didn't enter anything. set /p preserve existing value if user presses enter without typing anything. need set value default before issuing set /p.

problems can occur if user provides quotes arguments, , code adds additional quotes. safer use "%~1" - tilde strips existing quotes, , add own. works if argument quoted or not.

you should remove existing quotes when set ip in else statement.

you missing % when attempt expand ip argument adb. suspect want execute command. current code executes command if ip provided argument.

i structure code follows:

@echo off setlocal set "def=192.168.1.21" set "ip=%~1" if not defined ip (   set "ip=%def%"   echo please supply ip address of adb server/tablet.   set /p "ip=[%def%] " ) "c:\program files\adt-bundle-windows-x86_64-20130219\sdk\platform-tools\adb" connect "%ip%:5555" 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -