1

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?

0

1 Answer 1

2

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

& $env:PYTHON2PATH\python.exe

or

& "${env:PYTHON2PATH}\python.exe"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.