environment variable is blank

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
agrawal.meet
Posts: 15
Joined: 14 Jun 2010 06:50

environment variable is blank

#1 Post by agrawal.meet » 23 Jun 2010 03:00

Hi All,

I created one environment variable from My computer->properties->advanced->Environment variables->system variables.

Problem is: This compute is used for running bat files to process feeds and never shuts down. I just added this new variable in the bat file. When this bat file is called, this variable is appearing as <blank>. No values in it :cry: . But when I log on to this machine and echo the same variable...the value is shown correctly. :?

Do I have to restart/log off the machine? Please help. :)

Thanks,
Meet

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: environment variable is blank

#2 Post by amel27 » 23 Jun 2010 03:33

your must restart CMD session (not computer) or use SETX instead SET/Registry

agrawal.meet
Posts: 15
Joined: 14 Jun 2010 06:50

Re: environment variable is blank

#3 Post by agrawal.meet » 23 Jun 2010 04:28

How to restart cmd. There is no cmd running on that computer. A scheduler job calls .bat file at specific times. That's all. I am not setting this variable in bat file only using it.

Thanks,
Meet

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: environment variable is blank

#4 Post by amel27 » 23 Jun 2010 06:07

all .bat jobs, that started after change var may use this variable

agrawal.meet
Posts: 15
Joined: 14 Jun 2010 06:50

Re: environment variable is blank

#5 Post by agrawal.meet » 23 Jun 2010 06:20

Sorry for my ignorance but how do I restart .bat file (double click on it manually?)? It's production environment so I have to be careful.

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: environment variable is blank

#6 Post by amel27 » 23 Jun 2010 06:45

wait next call according to time schedule... :)
I cannot recommend kill BAT box in production environment

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

Re: environment variable is blank

#7 Post by aGerman » 23 Jun 2010 15:08

agrawal.meet

If you start a batch file, it gets the current environment as a "mirror image". This "mirror image" is valid as long as your batch process runs. You can change it "inside" the process, but never from "outside". That means, regardless what you would do with the parent environment, it would never touch the child environment of your batch process.

To that extent I've understood correctly, your batch file will never end or start new. In this case you can't work with a global variable which would change during the run time of your batch file. The only thing you can do with such a variable is to read the registry key where it is saved.
Otherwise you could try a different way, e.g. read a value from a file.

Regards
aGerman

agrawal.meet
Posts: 15
Joined: 14 Jun 2010 06:50

Re: environment variable is blank

#8 Post by agrawal.meet » 23 Jun 2010 23:01

wait next call according to time schedule... :)

It already ran 3 times (3 days) but the variable is still showing up as <blank> in log files

To that extent I've understood correctly, your batch file will never end or start new. In this case you can't work with a global variable which would change during the run time of your batch file.

I am not sure if I got it properly, but I am not changing the variable. Only using it. Below is the sample code.

System variable: GLOBENV_CAT_OUTDIR_ARCHIVE_GV
Value: \\<folder share>\CAT\Out Archive\GLOBAL VISION BACKUP

Use is the bat file:

Code: Select all

move "%GLOBENV_CAT_OUTDIR_ARCHIVE%\catgvf01.dat" "%GLOBENV_CAT_OUTDIR_ARCHIVE_GV%\catgvf01_D_%newDate%_%TIME%.dat"
move "%GLOBENV_CAT_OUTDIR_ARCHIVE%\catgvf02.dat" "%GLOBENV_CAT_OUTDIR_ARCHIVE_GV%\catgvf02_D_%newDate%_%TIME%.dat"
move "%GLOBENV_CAT_OUTDIR_ARCHIVE%\catgvf03.dat" "%GLOBENV_CAT_OUTDIR_ARCHIVE_GV%\catgvf03_D_%newDate%_%TIME%.dat"
move "%GLOBENV_CAT_OUTDIR_ARCHIVE%\catgvf04.dat" "%GLOBENV_CAT_OUTDIR_ARCHIVE_GV%\catgvf04_D_%newDate%_%TIME%.dat"


%GLOBENV_CAT_OUTDIR_ARCHIVE% variable which was already there from the start is working correctly.

Below is the log:

Code: Select all

D:\Apps\CAT\com>move "\\<folder share>\CAT\Out Archive\catgvf01.dat" "\catgvf01_D_20100624_00741.dat" 
        1 file(s) moved.

D:\Apps\CAT\com>move "\\<folder share>\CAT\Out Archive\catgvf02.dat" "\catgvf02_D_20100624_00741.dat"
        1 file(s) moved.

D:\Apps\CAT\com>move "\\<folder share>\CAT\Out Archive\catgvf03.dat" "\catgvf03_D_20100624_00741.dat"
        1 file(s) moved.

D:\Apps\CAT\com>move "\\<folder share>\CAT\Out Archive\catgvf04.dat" "\catgvf04_D_20100624_00741.dat"
        1 file(s) moved.

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

Re: environment variable is blank

#9 Post by aGerman » 24 Jun 2010 12:56

Stange.
-press keys [Windows]+[R]
-type CMD
-click OK
to open the command prompt

-type SET
-hit [Enter]
to display all global variables and their values

Can you find GLOBENV_CAT_OUTDIR_ARCHIVE_GV in this list?

Btw: Is there a command line in your batch file similar to this?:

Code: Select all

set GLOBENV_CAT_OUTDIR_ARCHIVE_GV=

Such command would destroy the variable for the code below that line.

Regards
aGerman

agrawal.meet
Posts: 15
Joined: 14 Jun 2010 06:50

Re: environment variable is blank

#10 Post by agrawal.meet » 24 Jun 2010 23:16

Hello aGerman,

Indeed it's strange. I ran set command in cmd and I can see the variable and it's value.
Btw: Is there a command line in your batch file similar to this?:

Code: Select all

set GLOBENV_CAT_OUTDIR_ARCHIVE_GV=


Nope, not setting this variable anywhere in the file

However, it's production system and I can't have this same problem repeating everyday. So, below is the fix I used.

Code: Select all

move "%GLOBENV_CAT_OUTDIR_ARCHIVE%\catgvf01.dat" "%GLOBENV_CAT_OUTDIR_ARCHIVE%\GLOBAL VISION BACKUP\catgvf01_D_%newDate%_%TIME%.dat"


Let me know if you are able to investigate this any further.

Thanks,
Meet

Post Reply