In Bash I can create TEMPORARY environment variables on a command line. For eample

DEBUG=foo somecommand

This sets the environmnet variable DEBUG but only for somecommand. When the line is finished DEBUG is no longer set.

Can I do something similar in the Windows Command Processor?

Note: Using SET does not work. That sets the current command processors environment, not the just for the command about to be executed.

To give another example here's a small node.js program that prints the value of a single environment variable

// test.js

Let's run it in bash

$ export FOO=abc
$ node test.js FOO

Then let's run it with a temporary setting

$ FOO=def node test.js FOO

Check that FOO is still abc

$ echo $FOO

How I can accomplish the same thing in the Windows command prompt?

One way seems to be to relaunch the command processor as in

cmd /S /C "set "FOO=def" & node test.js FOO"

Is there another way or is that it?

  • "Is there another way or is that it?" I think that is the only way. set foo=bar && echo %foo% && set foo= && echo %foo% does not work :(
    – DavidPostill
    Jan 28, 2018 at 7:32

1 Answer 1


Simply use the set command:

C:\>set foo=bar

C:\>echo %foo%


Open cmd again

C:\>echo %foo%

  • why do i keep getting notifications for this?
    – mekb
    Jun 28, 2021 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.