How to get os name,platform,version,kernel version and build

General FreeBASIC programming questions.
HACK3R ADI
Posts: 27
Joined: Jun 17, 2012 10:16

How to get os name,platform,version,kernel version and build

Postby HACK3R ADI » Sep 06, 2012 12:18

As the title says my question is How to get os name,platform,version,kernel version build date,cpu architecture and processor family
And .......
there is also one more condition that you will not use FB_Windows/FB_LINUX,etc... to get os name
codeFoil
Posts: 255
Joined: Dec 22, 2011 4:45
Location: United States
Contact:

Re: How to get os name,platform,version,kernel version and b

Postby codeFoil » Sep 07, 2012 23:33

This usually works. :)

Code: Select all

'SocialEngineering.bas
'Ryan Kelly (codeFoil) 2012
'
'=========================================================================|

Dim as String prompt(0 to ...) _
    => { "Operating System Name: ", _
         "Platform             : ", _
         "Version              : ", _
         "Kernel Version       : ", _
         "Build Date           : ", _
         "CPU Architecture     : ", _
         "Processor Family     : "  }

Dim as String reliableInfo(0 to UBound(prompt))

Print "Please supply the following information "
Print "to register to win FREE BEER!"
Print 'Blank Line
Print "* - Required"
Print 'Blank Line

For index as Integer = 0 to UBound(prompt)

    Print "*"; prompt(index);
    Input "", reliableInfo(index)

Next index

Print 'Blank Line
Print "Thank you kindly."
HACK3R ADI
Posts: 27
Joined: Jun 17, 2012 10:16

Re: How to get os name,platform,version,kernel version and b

Postby HACK3R ADI » Sep 08, 2012 12:19

If I have to do this way then why I make a thread on this you have to write a program which gets the whole use sys info.
Kot
Posts: 336
Joined: Dec 28, 2006 10:34

Re: How to get os name,platform,version,kernel version and b

Postby Kot » Sep 08, 2012 12:35

Code: Select all

Dim as String prompt(0 to ...)

Interesting :-o is it something like

Code: Select all

Dim as String prompt()

?
And use sleep at the end ;-)
fxm
Posts: 9949
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: How to get os name,platform,version,kernel version and b

Postby fxm » Sep 08, 2012 13:13

Kot wrote:

Code: Select all

Dim as String prompt(0 to ...)

Interesting :-o is it something like

Code: Select all

Dim as String prompt()

No exactly because the array remains static:
- upper bound fixed by the initializer,
- array un-resizable.
Kot
Posts: 336
Joined: Dec 28, 2006 10:34

Re: How to get os name,platform,version,kernel version and b

Postby Kot » Sep 09, 2012 8:42

Thanks.
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Re: How to get os name,platform,version,kernel version and b

Postby Gonzo » Sep 10, 2012 13:15

very nice solution :))

you can get most of the relevant info from simply reading enviroment variables
HACK3R ADI
Posts: 27
Joined: Jun 17, 2012 10:16

Re: How to get os name,platform,version,kernel version and b

Postby HACK3R ADI » Sep 10, 2012 14:58

I'm asking something but gettin' ans something.......
srvaldez
Posts: 2518
Joined: Sep 25, 2005 21:54

Re: How to get os name,platform,version,kernel version and b

Postby srvaldez » Sep 10, 2012 15:20

if I understand your question, you want a solution without using any system dependent API,
the only way is if such a function is implemented in the FB compiler.
Bob the Hamster
Posts: 31
Joined: Nov 16, 2005 5:47
Contact:

Re: How to get os name,platform,version,kernel version and b

Postby Bob the Hamster » Sep 10, 2012 15:42

HACK3R ADI wrote:there is also one more condition that you will not use FB_Windows/FB_LINUX,etc... to get os name


This is the reason you are not getting an asnwer to your question. You are asking for platform-specific information, then you need to use platform-specific code.
TJF
Posts: 3601
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: How to get os name,platform,version,kernel version and b

Postby TJF » Sep 10, 2012 16:35

As Bob the Hamster mentioned: It doesn't really make sence to look for platform-specific info without using platform specific code.

But you can use a trial-and-error method

Code: Select all

VAR win = 0, sh_co = "cat /proc/cpuinfo", fnr = FREEFILE
IF OPEN PIPE (sh_co FOR INPUT AS #fnr) THEN
  ? "Cannot execute shell command " & sh_co
ELSE
  VAR lin = ""
  IF EOF(fnr) THEN
    CLOSE fnr
  ELSE
    LINE INPUT #fnr, lin
    IF LEN(lin) THEN ' LINUX
      ?lin
      WHILE NOT EOF(fnr)
        LINE INPUT #fnr, lin
        IF LEFT(lin, 3) & MID(lin, 5, LEN(sh_co) - 3) = sh_co THEN win = 1 : EXIT WHILE
        ?lin
      WEND
      CLOSE fnr
      sh_co = "cat /proc/meminfo" : fnr = FREEFILE
      IF OPEN PIPE (sh_co FOR INPUT AS #fnr) THEN
        ? "Cannot execute shell command " & sh_co
      ELSE
        VAR lin = ""
        WHILE NOT EOF(fnr)
          LINE INPUT #fnr, lin
          ?lin
        WEND
        CLOSE fnr
      END IF
    ELSE ' win
      CLOSE fnr
      sh_co = "systeminfo" : fnr = FREEFILE
      IF OPEN PIPE (sh_co FOR INPUT AS #fnr) THEN
        ? "Cannot execute shell command " & sh_co
      ELSE
        WHILE NOT EOF(fnr)
          LINE INPUT #fnr, lin
          ?lin
        WEND
        CLOSE fnr
      END IF
    END IF
  END IF
END IF
codeFoil
Posts: 255
Joined: Dec 22, 2011 4:45
Location: United States
Contact:

Re: How to get os name,platform,version,kernel version and b

Postby codeFoil » Sep 11, 2012 0:02

srvaldez wrote:if I understand your question, you want a solution without using any system dependent API


That was my first impression, but I think now that he meant without using conditional compilation. I'm not sure if this was presented as a request for help or as a programming challenge. Perhaps XXXX3r ADI should clarify.
HACK3R ADI
Posts: 27
Joined: Jun 17, 2012 10:16

Re: How to get os name,platform,version,kernel version and b

Postby HACK3R ADI » Sep 16, 2012 15:27

Then someone can explain me how FB compiler gets OS info....
counting_pine
Site Admin
Posts: 6225
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: How to get os name,platform,version,kernel version and b

Postby counting_pine » Sep 16, 2012 16:27

The only thing the compiler knows is the platform it's compiling for. Your code can "know" what the compiler knows by checking for the Intrinsic defines such as __FB_LINUX__.
As far as I know there is no code in the compiler or runtime libraries that checks the kernel version. Particularly in the compiler, since the kernel version can only be known when the program is run, and of course it could be run on a different version of Linux to the one it's compiled on.

Return to “General”

Who is online

Users browsing this forum: No registered users and 3 guests