Imagine you have an app that needs to be configured with your local ip number before you start it, like Construct2. You could obtain ip address from powershell, but in some systems powershell is restricted to administrators.
You could use a python or sed script to get the IP address from command line, but, what if you want to use windows primitives only?
This batch file gets the exit of ipconfig, finds a local IPv4 address and returns it as a variable. (%IPv4%)
@echo off rem This batch file works in windows command line only. rem It needs extended commands like rem "exit /B", "for /F" y "set /A" rem if %1.==""K"". goto :findandexit if %1.==L. goto :ipfound rem "FOR" does not allow backquoted commands with pipes ("|"), so rem we will call this same file to execute "ipconfig | find IPv4" and rem gets the text after the first colon ":" on output text. rem The "\" delimiter is needed to get rid of spurious "C:\blah\blah\>" rem output generated on batch processing. for /F "usebackq tokens=2 delims=:\" %%a in (`%0 ""K""`) do call %0 L %%a exit /B goto :xit :ipfound rem testing for number... set IPV4t=%2 set IPV4t=%IPV4T:.=% set /A IPv4t=%IPV4t%-%IPV4t% if %ipv4t%==0 set IPV4=%2 set ipv4t= echo IPV4=%2 exit /B goto :xit :findandexit ipconfig |find "IPv4" exit /B goto :xit :xit