comp.lang.ada
 help / color / mirror / Atom feed
From: Rob Norris <firstname.lastname@baesystems.com>
Subject: Re: How to detect OS type and version?
Date: Fri, 14 Oct 2005 10:52:57 +0100
Date: 2005-10-14T09:43:13+00:00	[thread overview]
Message-ID: <vsvuk1dnnoqd9f81chcd2gj4mrtbajpjdj@4ax.com> (raw)
In-Reply-To: 434e4a25_1@glkas0286.greenlnk.net

On Thu, 13 Oct 2005 12:59:16 +0100, "Martin Dowie"
<martin.dowie@baesystems.com> 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;




  parent reply	other threads:[~2005-10-14  9:52 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-13  2:35 How to detect OS type and version? Roger Blum
2005-10-13  6:05 ` Martin Dowie
2005-10-13  9:50   ` Stefan Bellon
2005-10-13 10:39     ` Martin Dowie
2005-10-13 18:12     ` Jeffrey R. Carter
2005-10-13 18:37       ` Stefan Bellon
2005-10-13 21:21         ` Robert A Duff
2005-10-13 21:25           ` Stefan Bellon
2005-10-13 21:52             ` Robert A Duff
2005-10-16  0:13       ` Ray Blaak
2005-10-16  0:29         ` Robert A Duff
2005-10-16  4:48           ` Ray Blaak
2005-10-16 14:16             ` Larry Kilgallen
2005-10-16 15:55               ` Robert A Duff
2005-10-16 20:06               ` Pascal Obry
2005-10-18 16:58                 ` Ray Blaak
2005-10-16 15:59             ` Robert A Duff
2005-10-17 17:19               ` Ray Blaak
2005-10-13 18:11   ` Jeffrey R. Carter
2005-10-13 19:44   ` Simon Wright
2005-10-13 21:04   ` Michael Bode
2005-10-14  1:33     ` Steve
2005-10-13 12:06 ` Rob Norris
2005-10-13 11:59   ` Martin Dowie
2005-10-14  0:21     ` Randy Brukardt
2005-10-14  8:02       ` Martin Dowie
2005-10-14 23:27         ` Randy Brukardt
2005-10-15 12:28           ` Larry Kilgallen
2005-10-15 14:12             ` Martin Dowie
2005-10-14  9:52     ` Rob Norris [this message]
2005-10-13 20:25 ` Bernd Specht
2005-10-13 20:36   ` Michael Bode
2005-10-13 20:41     ` Bernd Specht
2005-10-13 20:58       ` Stefan Bellon
2005-10-14  0:27         ` Randy Brukardt
2005-10-15 19:48           ` Bernd Specht
2005-10-14  6:30 ` Roger Blum
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox