From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f890526de6a8a218 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!newsread.com!newsprint.newsread.com!newsfeed.stueberl.de!zen.net.uk!dedekind.zen.co.uk!news.anlx.net!caladan!news-peer-lilac.gradwell.net!not-for-mail From: Rob Norris Newsgroups: comp.lang.ada Subject: Re: How to detect OS type and version? Date: Fri, 14 Oct 2005 10:52:57 +0100 Message-ID: References: <22jsk1pnk6664cr4so2nig7ssi2u0d6bv7@4ax.com> <434e4a25_1@glkas0286.greenlnk.net> X-Newsreader: Forte Free Agent 2.0/32.652 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Original-NNTP-Posting-Host: glkas0286.greenlnk.net NNTP-Posting-Date: 14 Oct 2005 09:43:13 GMT NNTP-Posting-Host: 20.133.0.1 X-Trace: 1129282993 news.gradwell.net 38045 dnews/20.133.0.1 X-Complaints-To: news-abuse@gradwell.net Xref: g2news1.google.com comp.lang.ada:5637 Date: 2005-10-14T09:43:13+00:00 List-Id: On Thu, 13 Oct 2005 12:59:16 +0100, "Martin Dowie" wrote: >That way doesn't give the version of the OS. > I tried to imply that with "Not very exact, but may be useful"... Once you know the system is Unix like (including VMS??) they should have the 'uname -a' shell command which could be called by some Ada function that wraps around C pragma system call in stdlib.h. For Windows systems the command is 'ver'. Something like: with Interfaces.C.Strings; with Ada.Text_IO; -- -- function C_System (Command : in Interfaces.C.Strings.chars_ptr) return Integer; pragma Import (C, C_System, "system"); -- -- function Shell_Command (Command : in String) return Integer is C_Command : Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.New_String (Command); begin return C_System (C_Command); end Shell_Command; type os_type is (Unix, Windows, Unknown); -- -- function What_OS return os_type is begin if gnat.os_lib.directory_separator = '/' then if shell_Command ("uname -a") = -1 then Ada.Text_IO.Put_Line ("OS version inspection failed"); end if; return Unix; elsif gnat.os_lib.directory_separator = '\' then if shell_Command ("ver") = -1 then Ada.Text_IO.Put_Line ("OS version inspection failed"); end if; return Windows; else return Unknown; end if; end What_OS; procedure main is Ada.Text_IO.OS_Type'Image (what_os); end main;