Tjaart
Tjaart

Reputation: 496

Executing an Environment Variable based path in the Powershell Terminal

I want to execute a path in the Windows Powershell terminal based on the concatenation of an environment variable and a string, in one line.

For instance, cmd.exe allows me to execute the following:

c:\temp> %PYTHON2PATH%\python.exe main.py

With Powershell, it seems that one needs to refer to the environment variable using:

PS c:\temp> $Env:PYTHON2PATH\python.exe

Although this only works if I press TAB (which then de-references the variable), before pressing Enter. Is there is way do this without having to de-reference it using the TAB key?

Upvotes: 1

Views: 108

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200523

Use the call operator (&) if you want to invoke command strings with unexpanded variables:

& $env:PYTHON2PATH\python.exe

or

& "${env:PYTHON2PATH}\python.exe"

Upvotes: 2

Related Questions