SET Variable = Myproject

  • Thread starter Thread starter Joseph
  • Start date Start date
J

Joseph

How do I use (syntax/other) the SET name=othername in a batch file, on XP,
to set an environment variable?
So far... I've had no luck.

J
 
Joseph said:
How do I use (syntax/other) the SET name=othername in a batch file, on XP,
to set an environment variable?
So far... I've had no luck.

J

Using the old style control panel
Control Panel -> System -> Advanced tab -> Environment Variables
 
Thanks Carl,

I do not want the SET to be permanent. I know I can also hand key the new
'SET's from a CMD window, which is very time consuming.

I was looking for a way to 'automate' the job in a batch file (or similar)
so that when I'm done I can undo the SET's.

I've tried most nearly all of the obvious ways I know of, and still no luck.

J
 
Joseph said:
How do I use (syntax/other) the SET name=othername in a batch file, on XP,
to set an environment variable?
So far... I've had no luck.

The syntax is as you say:

set variable=value

If you put the following in a batch file, the output to the screen
should be X after running the batch:

@set x=X
@echo %X%

If that is not what you are attempting, post a specific example of what
you are trying to do that is failing.
--
Tom Porterfield
MS-MVP Windows
http://support.telop.org

Please post all follow-ups to the newsgroup only.
 
Joseph said:
I was looking for a way to 'automate' the job in a batch file (or similar)
so that when I'm done I can undo the SET's.

See $ help setlocal and
$ help endlocal
 
As standard (ie a programmer doesn't override the default), environments are copied then passed from the parent program to a child program. Explorer starts most programs in Windows.

So (assuming cmd),

Set a=dog
notepad

will start notepad with a variable named a available. If notepad should change this a variable then only notepad's environment is changed, not the calling cmd's.

So start cmd, set your variables (they disappear when you exit cmd), then start any programs from that cmd instance.

To run a batch and leave a command window open use

cmd /k batfile.bat
 
How do I use (syntax/other) the SET name=othername in a batch file, on XP,
to set an environment variable?
So far... I've had no luck.

What does this mean, "no luck"? What are you trying to do, and what
message did you get?

SET name=text works just fine, but it will not survive a reboot. For
that you need to go into System Properties (press Windows+Break
keys), Advanced tab, Environmental Variables button.

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
"What in heaven's name brought you to Casablanca?"
"My health. I came to Casablanca for the waters."
"The waters? What waters? We're in the desert."
"I was misinformed."
 
I do not want the SET to be permanent. I know I can also hand key the new
'SET's from a CMD window, which is very time consuming.

I was looking for a way to 'automate' the job in a batch file (or similar)
so that when I'm done I can undo the SET's.

See the setlocal command.

Or, create a second batch file with
set A=
set NAME=
and so forth -- that is, "set" commands with nothing after the = sign
will delete those environment variables.

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
"What in heaven's name brought you to Casablanca?"
"My health. I came to Casablanca for the waters."
"The waters? What waters? We're in the desert."
"I was misinformed."
 
I want to thank each of you for the information.

As I try, I discover that I can make the temporary enviroment variables,
example: SET DUM=dummy work from a batch file, say dum.bat, but ONLY if I
run the dum.bat file from within a CMD window. Then when the program
finishes I can undo the SET's from the same CMD window. This requires I also
run the program from the CMD window as well.

I was trying to run the batch file from 'explorer' (click on it), which did
not effect the environment changes set within the .bat file. I don't know
why.

The same file run from a CMD window, however, did make the changes.

I do not want to set the variables permanently.

Again thanks, I do have my workaround now.

Joe
 
How do I use (syntax/other) the SET name=othername in a batch file, on XP,
to set an environment variable?
So far... I've had no luck.

Below is the group where a lot batch discussion resides. The
environmental variable should persist as long as the batch file
that sets it is still running. I think when the batch closes, the
variable is also gone.

alt.msdos.batch.nt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top