Article
Evgeny Shvarov · Feb 13 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!

6
4 717
Discussion (22)2
Log in or sign up to continue

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

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 ;-)

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)"

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)"

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) }​​​​​

@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 "!":

!whoami
whoami - 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: whoami
irisusr

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

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

Thanks for the additional use-case :)

and that's the effective code behind

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

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)"

"reset" terminal session

%SYS 4d3>kill  zremove  quit
 
%SYS>

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.

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.

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!