1.

Solve : DOS environment variable?

Answer»

I try to store a file sequence NUMBER in an ENVIRONMENT variable.

these are the steps I took
run the command.exe from window XP
type SET filesequence = a on the command prompt
type SET to verify, it is there!
type EXIT to exit
Run the command.exe from window again
the environment variable filesequence disappears

is there a way to make the environment variable permanent?

I have the same problem when setting it in BAT program. When the program FINISHES, the variables set inside the program disappear. In DOS, are program variables and environment variables are defined differently?

thanks in advance for any help.Using set only creates an environment variable for the current session, but you can use the setx command to create persistent variables. Type setx /? to see the documentation.





Quote from: Salmon Trout on February 18, 2011, 02:20:58 PM

Using set only creates an environment variable for the current session, but you can use the setx command to create persistent variables. Type setx /? to see the documentation.

example:

setx filesequence a

You need to start a new command session to see the new variable

Note that to set the variable to a null value you can do

setx filesequence ""

but the registry entry will still be there. To completely remove it use the enviroment variables GUI.

Something you should note:

Your script that you showed contains too many spaces in the SET command.

This command: SET filesequence = a does not create a variable referred to by %filesequence% which expands to "a". It creates a variable referred to by %filesequence % which expands to " a". (The quotes are not part of the values, I included them to show the effect of the leading SPACE)

You need:

SET filesequence=a

See? No spaces. In the SET command syntax every character before the = character is part of the variable name and every character after the = is part of the variable value. This includes spaces. In fact this applies generally, e.g. in IF comparisons.


thanks very much for the information.

However, when I tried SETX, I got the message

N:\>setx fileseq=1
'SETX' is not recognized as an internal or external command,
operable program or batch file.

I am running C:\WINDOWS\system32\command.com

Do I need to turn on anything?

thanks.What operating system are you running? If Windows 2000 or after, why aren't you using cmd.exe?
Hi, I am running Window XP professional 2002, service pack 3. The same unrecognised SETX return when I execute it through CMD.EXE

thanks.Quote from: edwin.fung on February 22, 2011, 11:13:03 AM
Hi, I am running Window XP professional 2002, service pack 3. The same unrecognised SETX return when I execute it through CMD.EXE

thanks.

1. get it here

http://www.microsoft.com/downloads/en/confirmation.aspx?FamilyID=dc2d3339-8f36-4fba-a406-2a2a2ad7208c

2. You used the wrong syntax

Quote
However, when I tried SETX, I got the message

N:\>setx fileseq=1

You should use

setx fileseq 1

No equals sign. I showed you this above.




thanks a lot! It works! Quote from: edwin.fung on February 24, 2011, 12:18:47 PM
It works!

That is GOOD news!


Discussion

No Comment Found