Save/Load null variables

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
EliJamesMorey
Posts: 4
Joined: 21 Jan 2019 12:40

Save/Load null variables

#1 Post by EliJamesMorey » 15 Feb 2019 13:39

Is there any way to save null variables I have been saving and loading variables using.

(
echo %variable%
echo %variable2%
echo %variable3%
)>save.sav

and

(
set /p variable=
set /p variable2=
set /p variable3=
)<save.sav

This works fine, except that some variables are null (and I would like to keep them that way), and when
they have been saved and loaded, then they always show up as "ECHO is off." rather than just a blank.

What can I do to fix this? I want null variables to continue appearing as blank spaces even after loading.

Thanks in advance for your help.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Save/Load null variables

#2 Post by Squashman » 15 Feb 2019 13:58

Code: Select all

@echo off
set "variable=var1"
set "variable2="
set "variable3=var3"

(
echo.%variable%
echo.%variable2%
echo.%variable3%
)>save.sav

(
set /p variable=
set /p variable2=
set /p variable3=
)<save.sav

echo.%variable%
echo.%variable2%
echo.%variable3%

Pause

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Save/Load null variables

#3 Post by aGerman » 15 Feb 2019 14:01

some variables are null
I assume they are not defined. In that case you want to write an empty line into your file.

Code: Select all

(
  echo(%variable%
  echo(%variable2%
  echo(%variable3%
)>"save.sav"
Steffen

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Save/Load null variables

#4 Post by Ed Dyreen » 16 Feb 2019 10:19

some variables are null
NULL does exist as character but is used internally by cmd for delimiting variables in memory and cannot be assigned or it is used in the context of device during a redirection.

Post Reply