Written by

Senior Startups and Community Programs Manager at InterSystems Corporation
Article Evgeny Shvarov · Feb 13, 2022 2m read

One Liners - Useful ObjectScript Commands One Line Long

Folks!

Recently I found several one-line long ObjectScript commands on DC and think that it'd be great not to lose it and to collect more!

So I decided to gather a few first cases, put in one OEX project, and share them with you!

And here is how you can use them.

1. Create client SSL configuration.

set $namespace="%SYS", name="DefaultSSL" do:'##class(Security.SSLConfigs).Exists(name) ##class(Security.SSLConfigs).Create(name)

Useful if you need to read content from an URL.

Don't forget to return to a previous namespace. Or add 

n $namespace

before the call. Once you go up in the stack the namespace will be switched to your current namespace automatically.

Source.

2. Install ZPM

set $namespace="%SYS" do ##class(Security.SSLConfigs).Create("ssl") set r=##class(%Net.HttpRequest).%New(),r.Server="pm.community.intersystems.com",r.SSLConfiguration="ssl" do r.Get("/packages/zpm/latest/installer"),$system.OBJ.LoadStream(r.HttpResponse.Data,"c")

Useful, if you don't have ZPM in your IRIS and can install with this one call in the terminal.

Courtesy of @Guillaume Rongier and @Sergei Shutov and @Sergey Mikhailenko 

Source.
 

3. Create %All Namespace:

set $namespace="%SYS",P("Globals")="%DEFAULTDB",sc=##class(Config.Namespaces).Create("%All",.P)

Courtesy of @Eduard Lebedyuk and @Alexey Maslov 

Source

4. Enable IRIS BI in a current namespace:

do EnableDeepSee^%SYS.cspServer("/csp/"_$$$LOWER($namespace))

Courtesy of @Benjamin De Boe

Source.

Please add your useful lines :)  Collaboration is very welcome!

Comments

Evgeny Shvarov  Feb 13, 2022 to Sergey Mikhailenko

Snippets are great and deserve attention, but one-liners have a very certain use case, when you can execute it from the command line or as a docker image tweak

0
Sergey Mikhailenko · Feb 14, 2022

Propose No. 5 Create a new database and namespace with resources and mapping in interoperability and install a module from the register into it, for example "dc-one-liners"

At the end of line No. 2 of the zpm installation:

set $namespace="%SYS" do ##class(Security.SSLConfigs).Create("ssl") set r=##class(%Net.HttpRequest).%New(),r.Server="pm.community.intersystems.com",r.SSLConfiguration="ssl" do r.Get("/packages/zpm/latest/installer"),$system.OBJ.LoadStream(r.HttpResponse.Data,"c") zpm "install zapm" zapm "newdb dc-one-liners"

And you can create any number of such one-liners for all possible cases ;-)

0
Alexey Maslov · Feb 14, 2022

Or add 

n $namespace

before the call. Once you go up in the stack the namespace will be switched to your current namespace automatically.

It would not unless you exit the current stack level. To achieve it, you should perform the one-liner as an argument of Xecute command, making it less pleasant, e.g. 

x "new $namespace set $namespace=""%SYS"",P(""Globals"")=""%DEFAULTDB"",sc=##class(Config.Namespaces).Create(""%All"",.P)"
0
Alexey Maslov  Feb 14, 2022 to Alexey Maslov

you should perform the one-liner as an argument of Xecute command

Bonus: you can New other variables if you want, e.g. 

x "new $namespace,P set $namespace=""%SYS"",P(""Globals"")=""%DEFAULTDB"",sc=##class(Config.Namespaces).Create(""%All"",.P)"
0
Ben Spead · Feb 22, 2022

This is great, thank you Evgeny!!  Here is another one that I use, often from the Output window in Studio in order to execute an OS-level command (I most frequently use this for p4 commands to interact with my Perforce server from my IRIS server).  IIRC, original credit goes to @Timothy Leavitt 

Kill stream Set sc = ##class(%Studio.SourceControl.ISC).RunCmd("<insert OS Command here>",.stream,,1) w ! do stream.OutputToDevice() If 'sc {​​​​​ Write $System.Status.GetErrorText(sc) }​​​​​
0
Ben Spead  Feb 23, 2022 to Evgeny Shvarov

@Evgeny Shvarov  - you cannot use "!<cmd line>" from the Output window of Studio.  It is often very helpful to run a command from the context of a serverside Caché/InterSystems IRIS process which you can do via the Output Window with the above command, but not with "!":

!whoamiwhoami - Error <SYNTAX>Kill stream Set sc = ##class(%Studio.SourceControl.ISC).RunCmd("whoami",.stream,,1) w ! do stream.OutputToDevice() If 'sc { Write $System.Status.GetErrorText(sc) }CMD: whoamiirisusr

Again, this is particularly useful when running server-side source control commands (if you need to debug or augment hooks)

0
Robert Cemper  Feb 23, 2022 to Ben Spead

A typical use case is WebTerminal !

0
Ben Spead  Feb 23, 2022 to Robert Cemper

Good point Robert!

0
Evgeny Shvarov  Feb 23, 2022 to Robert Cemper

I'm not sure ) This is a command line, yes?

0
Ben Spead  Feb 23, 2022 to Robert Cemper

Thanks for the additional use-case :)

0
Robert Cemper  Feb 23, 2022 to Evgeny Shvarov

and that's the effective code behind

Set rc=$zf(-1,cmd_" 2> """_errorfile_""" > """_outputfile_"""")

0
Sergey Mikhailenko · Feb 23, 2022

Hey, here's another one-liner: Change password for preset users

x "new $namespace,s,p,n set $namespace=""%SYS"",p(""Password"")=""NewPass123"" for n=""admin"",""cspsystem"",""iam"",""superuser"",""unknownuser"",""_system"",""_ensemble"" set s=##class(Security.Users).Modify(n,.p)"
0
David Underhill · Mar 29, 2022

"reset" terminal session

%SYS 4d3>kill  zremove  quit
 
%SYS>
0
George James  Mar 29, 2022 to David Underhill

This would only kill variables at the current stack level.  I think you rather want to do:

%SYS 4d3>quit
 
%SYS>kill  zremove

Nevertheless a useful tip.  Many people don't seem to realize that they need to issue a quit to unwind the stack after an error.

0
David Underhill  Mar 29, 2022 to George James

Good point, I guess it depends on the variables scope at that stack level, I generally just run it twice.

Either way, as you say, it is useful to know to do this to ensure "leftovers" don't interfere with later commands.

0
Evgeny Shvarov · Apr 3, 2022

Added macro for all the one liners.

So you also can

include dc.one.Line

and call

$$$changealladminpass("pass") to change all the predefined passwords to "pass", and other useful one-liners you suggested.

The Line.cls file illustrates the usage.

Suggest your useful one-liners!

0
Evgeny Shvarov · Oct 26

Another one-liner suggested by @Robert Cemper recently:
 

k^SPOOLs%io=$I O 2 u 2ZW%anyvariable c 2 u %io

E.g. if you want to expose the content of %request during REST API method debugging, to write all the contents of %request to ^SPOOL global:

k^SPOOLs%io=$I O 2 u 2ZW%request c 2 u %io

and then ZW ^SPOOL in the terminal.

0