Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Running EXE file with environment variable in path (PowerShell)

I want to run some executable on Windows using PowerShell. Path to this executable should be resolved with environment variable.

For example

running command

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

C:\Windows\system32\cmd.exe

as

$Env:SystemRoot\system32\cmd.exe

I have tried this option and it raises following exception

At line:1 char:16
+ $Env:SystemRoot\system32\cmd.exe
+                ~~~~~~~~~~~~~~~~~
Unexpected token '\system32\cmd.exe' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

What is the right way to do it?

>Solution :

Tell the powershell to call the command by putting an ampersand in front &$Env:SystemRoot\system32\cmd.exe

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading