Formatting of command for external application

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of Gerald Gerald 1 year, 11 months ago.

  • Author
    Posts
  • #24806
    Profile photo of Gerald
    Gerald
    Participant

    I'm trying to execute a command against another application(PTC Integrity) and am having trouble getting it formatted correctly within PowerShell.

    I am able to add the –% parm to the command and get it to work by hard coding the search value(in this example – "abc (def)" ) –

    im issues --hostname=$host --user=$User --port=$Port --% --queryDefinition='((field[FRED] contains "abc (def)") and (field["Type"] = "Group Definition"))' --fields="ID"
    

    However I need to pass that search string as a variable to the command. Something like this –

    $Search = "abc (def)"
    im issues --hostname=$host --user=$User --port=$Port --queryDefinition='((field[FRED] contains $Search) and (field["Type"] = "Group Definition"))' --fields="ID"
    

    The Integrity app is returning this error with that query –

    *** The query and queryDefinition options are incompatible with an issue selection.

    Essentially the command isn't getting parsed correctly, and it believes I'm trying to pass an incorrect value with my queryDefinition statement.

    I've tried every combination of quotations and escapes I can think of here.

    Any thoughts as to how I should be formatting this properly?

    Thanks

  • #24811
    Profile photo of Gerald
    Gerald
    Participant

    I found the resolution here – [url]http://edgylogic.com/blog/powershell-and-external-commands-done-right/[/url]

    The variable needs to double escaped inside the string, once for Powershell using the backtick(`), and once for the parser using a backslash(\). So the variable ends up looking like this – \`"$Search\`"

    And the full command then look slike this –

    $Search = "abc (def)"
    im issues - -hostname=$host - -user=$User - -port=$Port - -queryDefinition="((field[FRED] contains \`"$Search\`") and (field[Type] = Group Definition))" - -fields="ID"
    

    Thanks

You must be logged in to reply to this topic.