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

1

12

I can't seem to call this executable correctly in my psake deploy script.

If I do this:

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

It simply outputs this (and is clearly not calling the executable - just outputting the value of that expression):

c:\ReloDotNet2_ServiceEndpoints\Archiver\NServiceBus.Host.exe /install

But if I do this:

exec { c:\ReloDotNet2_ServiceEndpoints\Archiver\NServiceBus.Host.exe /install }

I get the expected output from the executable.

How do I correctly call an executable with a variable in the path to the executable in psake? If this is actually a PowerShell issue, please feel free to correct the question to reflect that insight.

I

Teage answered 19/12, 2012 at 23:1 Comment(0)
U
16

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 + 2
4
C:\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.

Unavailing answered 19/12, 2012 at 23:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.