is there some redirect from a string to a variable in batch?
main.cmd
@setlocal enableextensions Enabledelayedexpansion
@echo off
set log=C:\log\test.log
set my_var=foo
set vars_to_check=my_var
call check_empty.cmd "%vars_to_check%" || goto :error_handler
check_empty.cmd
if "%1" == "" (
echo no param. >> !log!
exit /b 2
)
if not defined %1 (
echo the variable %1 is empty. >> !log!
exit /b 1
)
echo %1 has value %%1%%. >> !log!
exit /b 0
Now I did run main.cmd: I did expect the echo 'my_var has value foo.'. However, I just get 'the variable "%1" is empty.' Please note the quotes around %1. Therefore, I removed the quotes from the call in main.cmd and it almost worked, as I got the message: 'my_var has value %my_var%.'. At least I am arriving at the point where the variable is realized to be defined.
The problem with avoiding the quotes is that the next step would have been: pass multiple vars and loop the check...
set vars_to_check=my_var some_other_var something_else
and now I need the quotes so I can pass the variable...
checkbatch would be. Do you want a returnerrorlevel, test written to the console or file reporting the status of each variable in the list, or perhaps a variable reporting which variables were/were not defined?