How to transform a routine into a line to use in the terminal
Hello everyone,
I talked to a colleague and he said that at the other company he worked, they converted a routine into a line and used that in the terminal like a command. So, I want to know if we have this function native in Intersystems products, or maybe was a program they created, my colleague doesn't remember and this would be useful for me now.
Edit:
Example of function:
func1
set var="Test"write var
quit0Become a line command:
USER>set var="Test"write var quit0
Best Regards,
Flávio.
Comments
Yes there is a way since I have seen it.
The ZLOAD and ZREMOVE commands are combined. Here is a sample I was sent.
zr
zl
showAdmins() n rs1,rs2,rc1,rc2,$NAMESPACE,user,adminrole,roles
s$NAMESPACE="%SYS"s rs1=##class(%ResultSet).%New("Security.Roles:List")
d rs1.Execute("*","%Admin_Manage:U,%Admin_Operate:U,%Admin_Secure:U")
f s rc1=rs1.Next() q:rc1=0d
. s adminrole=rs1.Data("Name")
. s rs2=##class(%ResultSet).%New("Security.Users:List")
. d rs2.Execute("*",adminrole)
. f s rc2=rs2.Next() q:rc2=0w rs2.Data("Name"),"|",rs2.Data("Roles"),!
qd showAdminsI did a correction on my question, I want to know if become a line command to use in the terminal.
If you have a routine that's saved as MyRoutine.mac, that would be:
do $$^MyRoutine
If you have a method within the MyRoutine.mac called Process, it would be:
do $$Process^MyRoutine(myargs)
I did a correction on my question, I want to know if the function become a line command to use in the terminal.
Where is the function func1? If it's in a routine, you'd use do $$func1^MyRoutine where MyRoutine is whatever the routine is called.
It's a function *.mac. I want the code become a single line to use in the terminal.
Yes, you can absolutely do that. You separate statements with 2 spaces. Here's an example:
for i=1:1:10 {
write i,!
write i*10,!
}
This gives the same output:
for i=1:1:10 { write i,! write i*10,! }It also works without brackets, but IMHO is less readable:
for i=1:1:10 write i,! write i*10,!
Maybe something like this:
zl YourRoutineName
S cmd=""
f i=1:1:4 s cmd=cmd_$t(func+i)_" "
zr
w cmd //to see if it's ok
.png)
The trick is in using <TAB>, after the label in the first line, and before each line, I even can copy-paste the entire code from an editor to a terminal, I use iTerm in macOS, no idea how it works with other terminals.