User bio
404 bio not found
Member since Jun 15
Posts:
Rob has not published any posts yet.
Replies:
Rob Dewan · Jun 16 go to post

I think if you embed the "q" in a here-document or pipe your commands into cache that this should work

cache -U %SYS "Monitor^MIRROR"<<EOF
q
EOF
Rob Dewan · Jun 15 go to post

Howdy, Robert! 

I'm another Rob(ert) and I've been a longtime reader (and fan) of your posts here in the developer community. Thank you for elucidating this use case of XECUTE, I have not considered using this command in a here-document before and I admire your approach! I would also like to share some of the workarounds that I've used in the past to approach similar problems:

Escape newline characters in your here-document:

var="InterSystems"
irissession MYIRIS -U%SYS<<EOF
FOR i=1:1:10 {\
  W i,!\
}
W !,"Howdy, $var!",!
H
EOF

Split your string and join it on a space (easiest to use in perl and python IMHO):

import subprocess

# Let's interpolate a variable
var = "InterSystems"

# Build iris_cmd
iris_cmd = f"""
FOR i=1:1:10 {{
    W i,!
}}
W !,"Howdy, {var}!",! 
H
"""

# write one-big line
iris_cmd = ' '.join(iris_cmd.split()) +"\n"

# Run commands in an irissession
proc = subprocess.run(
    ['irissession', 'IRISHEALTH', '-U', '%SYS'],
    input=iris_cmd,
    check=True,
    capture_output=True,
    text=True
)

for line in proc.stdout.splitlines():
    print(line)

Have your here-document write a routine and execute it:

cls="Config.Databases"
mthd="ListFunc"
irissession MYIRIS -U%SYS<<EOF
ZI "zExecute(cls,mthd);"
ZI "  S rset=\$CLASSMETHOD(cls,mthd)"
ZI "  WHILE (rset.%Next()) {"
ZI "    W rset.Name,?20,rset.Directory,!"
ZI "  }"
D zExecute("$cls","$mthd")
H
Certifications & Credly badges:
Rob has no Certifications & Credly badges yet.
Followers:
Rob has no followers yet.
Following:
Rob has not followed anybody yet.