Sridhar Ratnakumar
Sridhar Ratnakumar

Reputation: 85302

Running a command with specific environment settings - one-liner

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?

Upvotes: 1

Views: 323

Answers (2)

Anders
Anders

Reputation: 101606

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)

Upvotes: 1

i_am_jorf
i_am_jorf

Reputation: 54600

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.

Upvotes: 1

Related Questions