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)'.png)
what's the right way to pass in text?
Comments
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:
thank you for confirming my approach, but unfortunately that's not how it works it seems.
PS C:\Users\Colin\Desktop> irissession healthconnect -U user 'Say^ImplUtil("Your String Here")'
<INVALID ARGUMENT>>Have you tried adding backticks to your double-quotes to escape them?
PS C:\Users\Colin\Desktop> irissession healthconnect -U user 'Say^ImplUtil(`"Your String Here`")'By the Power of ChatGPT it is: Triple Quotes.
Spoiler
# Test string escaping for IRIS session routine calls
param(
[string]$Instance = "healthconnect",
[string]$TestString = "Your String Here"
)
Write-Host "Testing string escaping for IRIS session routine calls" -ForegroundColor Cyan
Write-Host "Instance: $Instance" -ForegroundColor Yellow
Write-Host "Test String: '$TestString'" -ForegroundColor Yellow
Write-Host ""
# Array of different escape patterns to test
$escapeTests = @(
@{
Name = "Backtick quotes"
Pattern = 'Say^ImplUtil(`"' + $TestString + '`")'
},
@{
Name = "Single quotes around whole command"
Pattern = "Say^ImplUtil(""$TestString"")"
},
@{
Name = "Double quotes escaped with backslash"
Pattern = 'Say^ImplUtil(\"' + $TestString + '\")'
},
@{
Name = "Single quotes inside double quotes"
Pattern = "Say^ImplUtil('$TestString')"
},
@{
Name = "No quotes around string"
Pattern = "Say^ImplUtil($TestString)"
},
@{
Name = "Backtick escaped double quotes"
Pattern = "Say^ImplUtil(`"$TestString`")"
},
@{
Name = "Double backtick quotes"
Pattern = 'Say^ImplUtil(``"' + $TestString + '``")'
},
@{
Name = "Triple quotes"
Pattern = 'Say^ImplUtil("""' + $TestString + '""")'
},
@{
Name = "Percent encoding style"
Pattern = "Say^ImplUtil(%22$TestString%22)"
},
@{
Name = "Curly braces"
Pattern = "Say^ImplUtil({$TestString})"
}
)
$successfulPatterns = @()
foreach ($test in $escapeTests) {
Write-Host "Testing: $($test.Name)" -ForegroundColor White
Write-Host "Pattern: $($test.Pattern)" -ForegroundColor Gray
try {
# Test the pattern
$result = irissession $Instance -U user $test.Pattern 2>&1
# Check if it's an invalid argument error
if ($result -match "INVALID ARGUMENT" -or $result -match "ERROR" -or $result -match "SYNTAX ERROR") {
Write-Host "❌ FAILED: $result" -ForegroundColor Red
} else {
Write-Host "✅ SUCCESS: $result" -ForegroundColor Green
$successfulPatterns += $test
}
} catch {
Write-Host "❌ EXCEPTION: $_" -ForegroundColor Red
}
Write-Host ""
}
# Summary
Write-Host "=== SUMMARY ===" -ForegroundColor Cyan
if ($successfulPatterns.Count -gt 0) {
Write-Host "Successful patterns:" -ForegroundColor Green
foreach ($pattern in $successfulPatterns) {
Write-Host " ✅ $($pattern.Name): $($pattern.Pattern)" -ForegroundColor Green
}
} else {
Write-Host "No successful patterns found. Consider testing with a simpler command first." -ForegroundColor Yellow
}
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!
thank you, I'll try this. 😊
As a guess you need to escape something as powershell is stripping it off and then not passing it.
This is common on Unix shells