Multi-line terminal commands
Let's say I have this simple script file try.script
write 1 write 0
I can execute it in a terminal (csession) by calling:
csession cache < try.script
And I get the following output:
%SYS> 1 %SYS> 0
However I want to use a try catch block in my script:
try {
write 1/0
catch {}
haltBut as script is executed line by line, it's interpreted like this:
%SYS>
TRY {
^
<SYNTAX>
%SYS>
WRITE 1/0
^
<DIVIDE>
%SYS>
CATCH {}
^
<SYNTAX>
%SYS>I know that I can write it all in 1 line, but I'd rather not do that. Is there a way to feed multiline statement into Cache?
Comments
Why not put your code in a mac routine and call the routine from your script file. Might be easier.
It's executed during container build, so to load something I need a script.
Make your script create an INT routine and run it. Example try.script below. Your lines of code either begin with the TAB character or with a label followed by TAB.
zr
; Test routine created by try.script file
w !,"This is written by INT routine ",$t(+0)
w !," which is created from a script injected to csession."
zs MyBootRoutine
d ^MyBootRoutine
; Clean up
zr zs MyBootRoutine
hHere's an output I get:
USER> USER> USER> This is written by INT routine USER> which is created from a script injected to csession. USER> USER> D ^MyBootRoutine ^ <NOROUTINE> *MyBootRoutine USER> USER> USER>
Looks like it's still line-by-line execution.
It worked for me (2017.2.2 on Windows):
C:\InterSystems\Ens172\bin>CSESSION ENS172 < c:\s\try.script Node: TIN, Instance: ENS172 USER>zr USER> ; Test routine created by try.script file USER> w !,"This is written by INT routine ",$t(+0) USER> w !," which is created from a script injected to csession." USER>zs MyBootRoutine USER>d ^MyBootRoutine This is written by INT routine MyBootRoutine which is created from a script injected to csession. USER>; Clean up USER>zr zs MyBootRoutine USER>h C:\InterSystems\Ens172\bin>
Maybe your indented script lines (the ones to insert into the routine) aren't starting with $C(9)
Thank you, missed the TABs.
Script files are line oriented; there is no line-continuation convention. Each line is separate from any other. Lines beginning with a semicolon are considered comments. You can use blank lines liberally to improve readability. Normally, invalid lines are ignored. Script commands may be preceded by spaces and/or tabs.
This option
https://community.intersystems.com/post/terminal-multi-line-option
or the extended one with editor support
https://community.intersystems.com/post/terminal-multi-line-command-editor
could be useful.