How do I call exec in psake to an executable with a variable path? How do I call exec in psake to an executable with a variable path? powershell powershell

How do I call exec in psake to an executable with a variable path?


Classic PowerShell issue. Try this instead:

exec { & "$ArchiverOutputDir\NServiceBus.Host.exe" /install }

PowerShell not only executes commands, it also evaluates expressions e.g.:

C:\PS> 2 + 24C:\PS> "hello world"hello world

What you have given to PowerShell at the beginning of a pipeline is a string expression which it faithfully evaluates and prints to the console. By using the call operator &, you're telling PowerShell that the following thing is either the name of a command (in a string) to be executed or a scriptblock to be executed. Technically you could also use . "some-command-name-or-path". The only difference is that for PowerShell commands, & creates a new scope to execute the command in and . doesn't. For external exes it makes no difference as far as I can tell which one you use but & is typically used.