Question
· Jun 5

Pass a string to a routine from powershell

Hi Community,

i'm trying to figure out how to pass a string to a routine from Powershell:
 

####

ROUTINE ImplUtil

Say(pSomething = "hello, i'm the ROUTINE") public{
    w !,pSomething,!
}

####

call: irissession healthconnect -U user 'Say^ImplUtil(12345)'

what's the right way to pass in text?

Discussion (8)2
Log in or sign up to continue

To pass a string to a routine from PowerShell, you can use a syntax similar to the following example:

call: irissession healthconnect -U user 'Say^ImplUtil("Your String Here")'

In ObjectScript, to call a routine with an argument, you use the caret symbol (^) followed by the routine name, then the method with the argument in parentheses as shown in this syntax:

DO Say^ImplUtil(argument)

Here, argument can be a string such as "hello, I'm the ROUTINE" enclosed in quotation marks. This ensures the argument is passed correctly as a string [1].

Sources:

By the Power of ChatGPT it is: Triple Quotes.

 
Spoiler

Testing: Triple quotes
Pattern: Say^ImplUtil("""Your String Here""")
✅ SUCCESS:  Your String Here 

I'm fairly certain i tested this before though. 🤔

I tried your test script and at least on my Win2016 server running HealthShare 2017 in PowerShell, and none of the tests passed on my system. However... if you triple-quote the triple-quotes, I was able to get it to run. So, the test argument was:

        Name = "Triple-Triple Quotes"
        Pattern = 'Say^ImplUtil("""""""""' + $TestString + '""""""""")'

But... my original $TestString didn't have any spaces in it. Once I added spaces, it failed both the 'Triple Quotes' and the 'triple-triple quotes' tests... so with a bit more tinkering, I changed this:

$TestString = '"""Your String Here"""' 

and it passed the Triple Quote test but failed the Triple-Triple Quote test... so it looks like if the string has spaces you need six quotes on each side of the string, but if not you need nine.

I have not yet found a delimiter that would work in both cases (string with & without spaces) but I'll keep tinkering as I have time...

OK, I think I figured out a way that seems to work with both spaces & non-spaces in the strings...

You need to use the "Stop Parsing" token available in powershell: --%

With that, and the usual delimiting with double quotes in strings (I couldn't get it working with outer single quotes at the PS command prompt), this does seem to work:

# So, you can run the script this way (at the command line):

.\irissession healthconnect -U user --% "Say^ImplUtil(""""""Your string here"""""")"

and it should work. In your script, you would need to make these modifications:

[string]$TestString = "Test_string_without_spaces"
# or to test with spaces
[string]$TestString = "Test string with spaces"
# In the escape test:
Name = "Double-Triple quotes"
Pattern = 'Say^ImplUtil(""""""' + $TestString + '"""""")'
# and because we're changing how we parse the string when calling it,
# we need to add a secondary stage when parsing the command. In the first
# try loop after the foreach, change your code to this:
$zparams = ' --% ' + $test.Pattern + ' 2>&1'
# Test the pattern
$result = .\irissession $Instance -U user $zparams
# Should be the end of the modifications...

Note: My instances and namespaces are quite a bit different than yours, so I tried to adjust things back to how you had it from my testing, but if I wasn't quite successful, I apologize for any missteps.

Hope this helps!