views:

54

answers:

2

To run a program with custom env settings, we do this on Linux

$ MYVAR=23 ./foo.py

On Windows, the only way I know of is:

C:\> set MYVAR=23
C:\> .\foo.py
C:\> REM unset MYVAR here (but how?)

But can't this done be as an one-liner?

+1  A: 
set MYVAR=

Will unset it.

You can also use SETLOCAL and ENDLOCAL to limit the scope of your variables. Run help SETLOCAL and help GETLOCAL from the command line for more info.

Also check out the Cmd reference.

jeffamaphone
+1  A: 
set foo=bar&.\foo.py&set foo=

It should be noted that batch files are parsed one line at the time, so one liners like this are problematic there (setlocal ENABLEDELAYEDEXPANSION can help out in those cases)

Anders
Sridhar Ratnakumar
Anders