1

I need to run a command as a variable. I am doing

>$exec = "C:\Windows\system32\notepad.exe"
> $exec "C:\temp\test.txt"
At line:1 char:7
+ $exec "C:\temp\test.txt"
+       ~~~~~~~~~~~~~~~~~~
Unexpected token '"C:\temp\test.txt"' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

What is missing?

fhcat
  • 971
  • 2
  • 9
  • 28
  • 1
    In short: An executable path that is quoted or contains variable references must - for syntactic reasons - be invoked with `&`, the [call operator](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Operators#call-operator-); see [this answer](https://stackoverflow.com/a/57678081/45375) to the linked duplicate for details. – mklement0 Oct 25 '21 at 19:51

0 Answers0