Terminal tip: Running OS-level commands

When working at the Caché command prompt I sometimes want to run an operating system command on the server host. By prefixing my command line with ! or $ I can do this with ease. The following examples are from 2017.1 on Windows, but the feature is available on all versions and platforms:

USER>!dir
 
 Volume in drive C has no label.
 Volume Serial Number is 2EF9-50B3
 
 Directory of c:\intersystems\ens171\mgr\user
 
12/06/2017  12:41    <DIR>          .
12/06/2017  12:41    <DIR>          ..
02/02/2017  18:05        11,534,336 CACHE.DAT
16/06/2017  12:05                36 cache.lck
07/11/2016  17:18    <DIR>          stream
               2 File(s)     11,534,372 bytes
               3 Dir(s)  83,540,684,800 bytes free
USER>$dir
 
 Volume in drive C has no label.
 Volume Serial Number is 2EF9-50B3
 
 Directory of c:\intersystems\ens171\mgr\user
 
12/06/2017  12:41    <DIR>          .
12/06/2017  12:41    <DIR>          ..
02/02/2017  18:05        11,534,336 CACHE.DAT
16/06/2017  12:05                36 cache.lck
07/11/2016  17:18    <DIR>          stream
               2 File(s)     11,534,372 bytes
               3 Dir(s)  83,075,710,976 bytes free
USER>
 

If I need to issue more than one command I can almost get myself an interactive shell:
 
USER>!
 
c:\intersystems\ens171\mgr\user\> dir
 Volume in drive C has no label.
 Volume Serial Number is 2EF9-50B3
 
 Directory of c:\intersystems\ens171\mgr\user
 
12/06/2017  12:41    <DIR>          .
12/06/2017  12:41    <DIR>          ..
02/02/2017  18:05        11,534,336 CACHE.DAT
16/06/2017  12:05                36 cache.lck
07/11/2016  17:18    <DIR>          stream
               2 File(s)     11,534,372 bytes
               3 Dir(s)  83,075,211,264 bytes free
c:\intersystems\ens171\mgr\user\>
c:\intersystems\ens171\mgr\user\> date
The current date is: 23/06/2017
Enter the new date: (dd-mm-yy)
c:\intersystems\ens171\mgr\user\>
c:\intersystems\ens171\mgr\user\> exit
USER>

I wrote "almost" because in the example above the 'date' command prompted me to enter a new date but didn't wait for my keystrokes. It behaved as though I had immediately pressed Enter.

Still, I find it a useful feature.

To use it you will need the %System_Callout:USE privilege.

More documentation here.

  • + 4
  • 0
  • 641
  • 5

Comments

My research shows that "!" was added in 1992, inspired by MSM. "$" was added in 1993 as a VMS-friendly synonym.

This tip has saved me a ton of hassle in a number of occasions.  One thing to note is that you will inherit the OS user that Caché is running under, so always remember to select your operating user carefully when installing Caché, so as to not give terminal users network access that they may not otherwise have

enlightened The article is considered as InterSystems Data Platform Best Practice.