I am working on this python script which is to be executed using BAT file. The Batch file takes 3 parameters. If the user gives no parameters ( NULL ) while executing BAT file, the code should assign values to the 3 variables. ( repo_path, py_file_path, branch )
How does IF ELSE condition work in BAT? I tried if %abc%=="" ( ) it did not work!! In fact the IF condition is failing.
Below is my code.
cls
set repo_path=%1
set py_file_path=%2
set branch=%3
IF [%repo_path%] == [] GOTO assign
:assign
set repo_path="C:\GIT\Analysis\360-analysis"
set py_file_path="C:\GIT\Analysis\360-analysis\NJ\WIP-Sai\Auto_Git_Project\Python_Files"
set branch="master"
echo %repo_path%
cd %repo_path%
python %py_file_path%\Auto_Git_Pull.py %branch%
pause
if %abc%==""actually comparesstringwith"string"...If Not Defined repo_path set "repo_path=C:\GIT\Analysis\360-analysis". For the purposed of this exercise however, you could probably useIf "%~3" == "" GoTo …==you should use EQU, it might work. As for null values, there really isn't a specific null operator in batch. I would just create another variable with blank content and call it null. There is technically a null variable which isnulas used in>nulto silence outputs, but it cannot be used in comparisons like if.echo %1. On the next line, typeif "%1"=="" echo Empty. Save the file asstringtest.bat. Run it from the command prompt asstringtest 1, and you'll see that it outputs1and nothing else. Run it again withstringtestand nothing else, and you'll seeECHO is ONfollowed byEmpty.