determine operating system

K

Kevin A

Hi,
Is there a way to determine the name and version of the
operating system in a portable way? (for Solaris/Linux)


Thanks,

Kevin
 
J

Julie

Kevin said:
Hi,
Is there a way to determine the name and version of the
operating system in a portable way? (for Solaris/Linux)

Thanks,

Kevin

Short answer: no

Long answer: no
 
J

Julie

bartek said:
Right answer: it depends

See http://predef.sourceforge.net/

On the contrary (and contrary to what is said in the link), those compiler
defines tell nothing of the actual operating system (or version), but at most,
tell the intended target operating system.

Right answer: no

If the OP wants a better answer, then they need to clarify as to specifically
what they are after as their post leaves a *lot* of room for
(mis)interpretation.
 
B

bartek

Julie said:
On the contrary (and contrary to what is said in the link), those
compiler defines tell nothing of the actual operating system (or
version), but at most, tell the intended target operating system.

Right answer: no

If the OP wants a better answer, then they need to clarify as to
specifically what they are after as their post leaves a *lot* of room
for (mis)interpretation.

Therefore the good answer (from the OP's pov) is dependent on the OP's
particular requirements, i.e. what degree of portability is important for
the OP. The original message provides a clear indication that it's not
about absolute portability, in which case the strict answer 'no' is
misleading, at least. Of course, I'm not saying it isn't informative.
 
J

Joe Cipale

Kevin said:
Hi,
Is there a way to determine the name and version of the
operating system in a portable way? (for Solaris/Linux)

Thanks,

Kevin

have you checked the man page for uname?
uname -a: returns all avaialble info for the given machine/OS.

Take a look at uname.
--
#----------------------------------------------------------#
# Penguinix Consulting #
#----------------------------------------------------------#
# Software development, QA and testing. #
# Linux support and training. #
# "Don't fear the penguin!" #
#----------------------------------------------------------#
# Registered Linux user: #309247 http://counter.li.org #
#----------------------------------------------------------#
 
D

Denis Remezov

Joe said:
have you checked the man page for uname?
uname -a: returns all avaialble info for the given machine/OS.

Take a look at uname.
--

Second that, but type

man 2 uname

Says it's POSIX.1. All reasonably modern Unices should be covered (SVr4
for sure), Linux too.

Certainly not C++, but while we are [OT] at it, it's about as portable
as it gets.

:)

Denis
 
J

Julie

Joe said:
have you checked the man page for uname?
uname -a: returns all avaialble info for the given machine/OS.

Take a look at uname.

Not portable, nor standard C++.
 
K

Kevin A

If the OP wants a better answer, then they need to clarify as to
specifically
what they are after as their post leaves a *lot* of room for
(mis)interpretation.

We are working on a project for school (university). We work on a server
that
runs Solaris, but some of us also work on our project at home using their
Linux.

For now I have solved this problem with a (ugly) temporary solution:

QString OS::getOperatingSystem() {
return "Solaris 8";
}

But under Linux this, of course, gives the wrong result.

As you can see (from the use of QString), we use Qt. Maybe Qt has a way to
get
the name and version of the OS. But I can not find anything yet.
On the contrary (and contrary to what is said in the link), those compiler
defines tell nothing of the actual operating system (or version), but at most,
tell the intended target operating system.

We compile on the same platform we run the program, so this IS a possible
solution. But if possible I would like a more elegant solution than using
macro's.


Kevin
 
J

Jorge Rivera

Kevin said:
We are working on a project for school (university). We work on a server
that
runs Solaris, but some of us also work on our project at home using their
Linux.

For now I have solved this problem with a (ugly) temporary solution:

QString OS::getOperatingSystem() {
return "Solaris 8";
}

But under Linux this, of course, gives the wrong result.

As you can see (from the use of QString), we use Qt. Maybe Qt has a way to
get
the name and version of the OS. But I can not find anything yet.




We compile on the same platform we run the program, so this IS a possible
solution. But if possible I would like a more elegant solution than using
macro's.


Kevin

More elegant solution????

Commercial code like Qt uses a lot of macros for system dependent things.

They handle compatibility with autoconf automake, which generates the
appropriate macro definitions and makefiles for compiling in your system.

#ifdef linux
or #ifdef Linux

should just work, specially when all you have to comply is with Linux
and Solaris compatibility.

another thing you can try is using make rules.

Have your makefile include a golbal rules file

localrules.$(OSNAME)

eg

localrules.Linux
localrules.Solaris

You can use 'uname' to use the rules that apply to the system you are
compiling on, and maybe define compile time variables -DLIN_COMP_VAR.

Again, this is one of the things macros are good for. Don't be afraid
to use them....

Jorge L.
 
J

Joe Cipale

Julie said:
Not portable, nor standard C++.

Funny...

works the same on my BSD/Solaris/Linux machines (just a small sample)...
~sheesh~

--
#----------------------------------------------------------#
# Penguinix Consulting #
#----------------------------------------------------------#
# Software development, QA and testing. #
# Linux support and training. #
# "Don't fear the penguin!" #
#----------------------------------------------------------#
# Registered Linux user: #309247 http://counter.li.org #
#----------------------------------------------------------#
 
J

Joe Cipale

Julie said:
So is your point that it is standard C++ and/or portable?

it is portable...
--
#----------------------------------------------------------#
# Penguinix Consulting #
#----------------------------------------------------------#
# Software development, QA and testing. #
# Linux support and training. #
# "Don't fear the penguin!" #
#----------------------------------------------------------#
# Registered Linux user: #309247 http://counter.li.org #
#----------------------------------------------------------#
 
K

Kevin A

#ifdef linux
or #ifdef Linux

should just work, specially when all you have to comply is with Linux
and Solaris compatibility.

I just found a reason why this is not the solution I'm looking for.
I'd like to have the entire name of the OS, something like
"Suse Linux" and its version number.
But the macro's can only answer: "is it Linux, yes or no?"


Kevin
 
K

Kevin A

have you checked the man page for uname?
uname -a: returns all avaialble info for the given machine/OS.

I just looked at the manpages for uname and I tried "uname -sr".
However, I was a little surprised by the result, since it printed
"SunOS 5.8" and the comments that appear when I log in remotely
to the server say that it runs Solaris 8. (If those two are the same,
please tell me)

And another thing: how can I call this from our C++ code?
I suppose using the system() function. But then, how can I get the
result that this function prints?


Kevin
 
J

Julie

Kevin said:
I just looked at the manpages for uname and I tried "uname -sr".
However, I was a little surprised by the result, since it printed
"SunOS 5.8" and the comments that appear when I log in remotely
to the server say that it runs Solaris 8. (If those two are the same,
please tell me)

And another thing: how can I call this from our C++ code?
I suppose using the system() function. But then, how can I get the
result that this function prints?

None of this is on topic, relevant, or able to be answered within this forum.

Your best bet is to take your question to a Solaris/Unix/Linux forum and post
it there.
 
M

Marc

"Kevin A" wrote :
I just looked at the manpages for uname and I tried "uname -sr".
However, I was a little surprised by the result, since it printed
"SunOS 5.8" and the comments that appear when I log in remotely
to the server say that it runs Solaris 8. (If those two are the same,
please tell me)

Indeed they are. Well actually one is only the operating system and the
other one includes the remaining tools, but basically it is the same.
And another thing: how can I call this from our C++ code?
I suppose using the system() function. But then, how can I get the
result that this function prints?

try "man 2 uname" instead of "man uname".
 
J

Jorge Rivera

Kevin said:
I just found a reason why this is not the solution I'm looking for.
I'd like to have the entire name of the OS, something like
"Suse Linux" and its version number.
But the macro's can only answer: "is it Linux, yes or no?"


Kevin
You can get uname to give you more insight. I dont't rember what
exactly, but uname will indeed give you more information than just Linux
or Solaris, although I don't know if Suse will be in the information.

From there on, you will then need to define your own macros given the
information requested.

I do really think that all your problems can be solved through the use
of autoconf automake, but you'll have to do your own research on this...

Jorge L.
 
J

Jorge Rivera

Not in the std C++ sense.

I guess that the point here is how to do this. You are correct, and so
are they. Among any Unix variant, uname is great, and hence it is
protable...

JLR
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top