Question
· Nov 9, 2018

How to get running operating system

Can anyone tell me how to discover in ObjectScript the operating system and operating system version that Caché is actually running in? (Not the operating system the build was compiled for.)

Discussion (11)2
Log in or sign up to continue

Thanks, Robert - really great to hear from you. I hope you are well.

And very interesting to learn about $systeminfo - it certainly provides a wealth of information about the environment. Unfortunately $systeminfo takes a few seconds to run, which is too slow when it might be required for many messages. I'll keep looking! If all else failsI guess I could get the information from $systeminfo when my business operation starts, and hold it in the business operation properties. So if you do happen to come across the equivalent for Linux and other platforms, please let me know.

You can use $version(1) to see if it is Windows (returns '2') or UNIX (returns '3').  If you want to get really fancy you can include %occOptions.inc and then use the $$$isUNIX and $$$isWINDOWS calls (which just check to see if $version(1) is 2 or 3).

Personally, I like using ##class(%Studio.SourceControl.ISC).RunCmd() as it wraps the capture of the output for parsing.

You can tie $version together the other answers into something that is platform independent (warning, I haven't tested this, but I believe the pieces work):

If ($version(1)=2) {

   //Is Windows

   set sc=##class(%Studio.SourceControl.ISC).RunCmd("Ver",.out,0)

   set OS = out(1)

   // exercise of parsing exact desired version piece from the string is an exercise left to the reader

} elseif ($version(1)=3) {

   //Is UNIX

   set sc=##class(%Studio.SourceControl.ISC).RunCmd("uname -a",.out,0)

   set OS = out(1)

   // exercise of parsing exact desired version piece from the string is an exercise left to the reader

}
Hope that helps you Paul!