0

I was trying to, from powershell, to make an executable to run another program like this:

PS> $env:userprofile\program.exe $env:userprofile\program2.exe

doing this I get

At line:1 char:17
+ $env:userprofile\program.exe $env:userprofile\program2.exe
+                 ~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'program.exe' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

both programs are in the same folder

Is such thing possible?

rajid17
  • 1
  • 1
  • 2
    try it like this `& "$env:userprofile\program.exe" "$env:userprofile\program2.exe"` – Santiago Squarzon Sep 09 '22 at 23:25
  • Wouldn't program.exe have to be installed in the UserProfile folder? Rather than in C:\Program Files, etc.? – RetiredGeek Sep 09 '22 at 23:29
  • @RetiredGeek In this case not necessarily – rajid17 Sep 09 '22 at 23:34
  • 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 the linked duplicate for details. – mklement0 Sep 10 '22 at 01:26

0 Answers0