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

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

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

Post by HACK3R ADI »

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: 256
Joined: Dec 22, 2011 4:45
Location: United States
Contact:

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

Post by codeFoil »

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

Post by HACK3R ADI »

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

Post by Kot »

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
Moderator
Posts: 12577
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

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

Post by fxm »

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

Post by Kot »

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

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

Post by Gonzo »

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

Post by HACK3R ADI »

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

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

Post by srvaldez »

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

Post by Bob the Hamster »

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: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

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

Post by TJF »

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: 256
Joined: Dec 22, 2011 4:45
Location: United States
Contact:

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

Post by codeFoil »

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

Post by HACK3R ADI »

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

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

Post by counting_pine »

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.
Post Reply