I'm trying to invoke another application (Beyond Compare) from Powershell which requires an @ in the typical command-line:
C:\deploy>bcompare @static.diff
I've found Powershell's Invoke-Expression, but when I try the following it gives me an error:
PS C:\deploy>Invoke-Expression "bcompare @static.diff"
Invoke-Expression : Cannot expand the splatted variable '@static'. Splatted variables
cannot be used as part of a property or array expression. Assign the result of the
expression to a temporary variable then splat the temporary variable instead.
At line:1 char:18
+ Invoke-Expression <<<< "bcompare @static.diff"
+ CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException
+ FullyQualifiedErrorId : NoPropertiesInSplatting,Microsoft.PowerShell.Comands.InvokeExpressionCommand
I can't get the @ to escape properly here. I've tried the `, @@, putting parts of the command in a temporary variable, but none of them did the trick.
bcompare '@static.diff'
If in doubt, put it into a string :-)
PS Home:\> args '@static.diff'
argv[0] = "C:\Users\Joey\Batches\args.cmd"
argv[1] = @static.diff
When I ran into the same problem, I used a backtick to make the @-sign interpreted literally. I wanted to use double-quotes for variable handling as well:
Invoke-Expression "& bcompare `@$compareCommands $file1 $file2"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With