473,396 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

determine operating system

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

Kevin
Jul 22 '05 #1
27 6737
Kevin A wrote:

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
Jul 22 '05 #2
Julie <ju***@nospam.com> wrote in news:40***************@nospam.com:
Kevin A wrote:

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


Right answer: it depends

See http://predef.sourceforge.net/

--
:: bartekd [at] o2 [dot] pl

Jul 22 '05 #3
bartek wrote:

Julie <ju***@nospam.com> wrote in news:40***************@nospam.com:
Kevin A wrote:

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


Right answer: it depends

See http://predef.sourceforge.net/

--
:: bartekd [at] o2 [dot] pl


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.
Jul 22 '05 #4
Julie <ju***@nospam.com> wrote in news:40***************@nospam.com:
bartek wrote:

Julie <ju***@nospam.com> wrote in news:40***************@nospam.com:
> Kevin A wrote:
>>
>> 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


Right answer: it depends

See http://predef.sourceforge.net/

--
:: bartekd [at] o2 [dot] pl


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.

--
:: bartekd [at] o2 [dot] pl

Jul 22 '05 #5
Kevin A wrote:

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 #
#----------------------------------------------------------#
Jul 22 '05 #6
Joe Cipale wrote:

Kevin A wrote:

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.


Not portable, nor standard C++.
Jul 22 '05 #7
> 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
Jul 22 '05 #8
Joe Cipale wrote:

Kevin A wrote:

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


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
Jul 22 '05 #9
Kevin A wrote:
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


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.
Jul 22 '05 #10
Julie wrote:

Joe Cipale wrote:

Kevin A wrote:

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.


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 #
#----------------------------------------------------------#
Jul 22 '05 #11
Joe Cipale wrote:

Julie wrote:

Joe Cipale wrote:

Kevin A wrote:
>
> 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.


Not portable, nor standard C++.


Funny...

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


So is your point that it is standard C++ and/or portable?
Jul 22 '05 #12
Julie wrote:

Joe Cipale wrote:

Julie wrote:

Joe Cipale wrote:
>
> Kevin A wrote:
> >
> > 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.

Not portable, nor standard C++.


Funny...

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


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 #
#----------------------------------------------------------#
Jul 22 '05 #13
Joe Cipale wrote:

Julie wrote:

Joe Cipale wrote:

Julie wrote:
>
> Joe Cipale wrote:
> >
> > Kevin A wrote:
> > >
> > > 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.
>
> Not portable, nor standard C++.

Funny...

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


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


it is portable...


Not in the std C++ sense.
Jul 22 '05 #14
> #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
"Jorge Rivera" <jo*****@rochester.rr.com> schreef in bericht
news:gQ********************@twister.nyroc.rr.com.. . Kevin A wrote:
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 compilerdefines 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


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.

Jul 22 '05 #15
> 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
"Joe Cipale" <jo**@aracnet.com> schreef in bericht
news:40***************@aracnet.com... Kevin A wrote:

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 #
#----------------------------------------------------------#

Jul 22 '05 #16
Kevin A wrote:
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?


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.
Jul 22 '05 #17
"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".
Jul 22 '05 #18
Kevin A wrote:
#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

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.

Jul 22 '05 #19
> 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
Jul 22 '05 #20
Joe Cipale wrote:
Julie wrote:
Joe Cipale wrote:
Julie wrote:

Joe Cipale wrote:

>Kevin A wrote:
>
>>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.

Not portable, nor standard C++.

Funny...

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


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

it is portable...


I tried this on VRTX operating system. No such command.
I tried this on MSDOS operating system. No such command.
I tried this on VAX operating system. No such command.
I tried this on our custom OS for an embedded system. No such command.

How could it be portable?
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #21
Jorge Rivera wrote:
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


But it is only protable [sic] to *Nix operating systems.
There are plenty of operating systems out there that
are neither MS Windows or *NIX.

For example, the MS-DOS operating system doesn't have uname.
Neither does: VAX, VRTX, nor custom operating systems.
Don't assume that the entire world has your operating system.
Many embedded systems either have no operating system,
proprietary OS or off-the-shelf OS. Many of which don't
support file systems or the uname command.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #22
Thomas Matthews wrote:
How could it be portable?


It is portable, within a certain domain. You can 'carry' it from one
UNIX-like system to another. The word is being used in a sensible way.
Standard C++ is not "portable" if that means it has to work for every
computer ever built.

--
Regards,
Buster.
Jul 22 '05 #23
Buster wrote:

Thomas Matthews wrote:
How could it be portable?
It is portable, within a certain domain.


Then it is of no interrest to comp.lang.c++
Plain and simple.
You can 'carry' it from one
UNIX-like system to another. The word is being used in a sensible way.
Standard C++ is not "portable" if that means it has to work for every
computer ever built.


Exactly that is the intent of Standard C++.
IF there is a C++ compiler on that machine AND
that compiler is standard compliant AND
the program uses only standard C++ constructs AND
the program doesn't contain undefined behaviour

THEN
the compiler can compile that program and
a program run will produce identical output

Granted: There is only 1 compiler currently known which is fully
standard compliant. But all the others are close to it and the
non standard compliant areas in them mostly deal with 'esoteric'
corners of the language which are not used by many programmers.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #24
> Short answer: no

Long answer: no


Then C++ is too limited :)
Kevin
Jul 22 '05 #25
Karl Heinz Buchegger wrote:

Buster wrote:

Thomas Matthews wrote:
How could it be portable?


It is portable, within a certain domain.


Then it is of no interrest to comp.lang.c++
Plain and simple.
You can 'carry' it from one
UNIX-like system to another. The word is being used in a sensible way.
Standard C++ is not "portable" if that means it has to work for every
computer ever built.


Exactly that is the intent of Standard C++.
IF there is a C++ compiler on that machine AND
that compiler is standard compliant AND
the program uses only standard C++ constructs AND
the program doesn't contain undefined behaviour

THEN
the compiler can compile that program and
a program run will produce identical output

Granted: There is only 1 compiler currently known which is fully
standard compliant. But all the others are close to it and the
non standard compliant areas in them mostly deal with 'esoteric'
corners of the language which are not used by many programmers.

--


Agreed Karl...
--
#----------------------------------------------------------#
# Penguinix Consulting #
#----------------------------------------------------------#
# Software development, QA and testing. #
# Linux support and training. #
# "Don't fear the penguin!" #
#----------------------------------------------------------#
# Registered Linux user: #309247 http://counter.li.org #
#----------------------------------------------------------#
Jul 22 '05 #26
Thomas Matthews wrote:

But it is only protable [sic] to *Nix operating systems.
There are plenty of operating systems out there that
are neither MS Windows or *NIX.


The person who posted the original question posted it regarding *nix
operating systems.

Joe
--
#----------------------------------------------------------#
# "Don't fear the penguin!" #
#----------------------------------------------------------#
# Registered Linux user: #309247 http://counter.li.org #
#----------------------------------------------------------#
Jul 22 '05 #27
Karl Heinz Buchegger wrote:
Exactly that is the intent of Standard C++.
IF there is a C++ compiler on that machine AND
that compiler is standard compliant AND
the program uses only standard C++ constructs AND
the program doesn't contain undefined behaviour
the program doesn't contain implementation-defined behavior
the program doesn't contain unspecified behavior
the program doesn't contain locale-specific behavior
I-D is a special case of unspecified behavior, of course.

THEN
the compiler can compile that program and
a program run will produce identical output


Brian Rodenborn
Jul 22 '05 #28

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nathan Sokalski | last post by:
I want to determine the operating system using ASP (or VBScript inside of ASP). I tried to get it using the Request. ServerVariables(EnvironmentVariable) method. On the web page about ASP in which...
3
by: lucpustjens | last post by:
Hello, I want te determine the client operating system, because I need to kno the default cookie directory. If there is a way to determine the cooki directory directly, than it is also good. ...
3
by: Sisyphus | last post by:
Hi, Is there anything in the ANSI C standard covering the means by which I can determine the operating system and compiler being used (at the preprocess stage) ? If so, then how might I...
12
by: Sunner Sun | last post by:
Hi, all Since the OS look both ASCII and binary file as a sequence of bytes, is there any way to determine the file type except to judge the extension? Thank you!
6
by: Kaki | last post by:
Given a file, how do I know if it's ascii or unicode or binary? And how do I know if it's rtf or html or etc? In other words, how do I find the stream type or mime type? (No, file extension cannot...
4
by: Alex Vincent | last post by:
HI all, I'm storing images, jpgs/gifs/png/bmps and also some other binary files in a SQL image field in a SQL 2k database. Most of the images enter the database via a asp.net webform upload,...
7
by: Ian F. Hood | last post by:
Hi In typically windows environments I have used: if 'Windows' in os.environ... to prove it, but now I need to properly support different environments. To do so I must accurately determine what...
4
by: Kenaso | last post by:
I know this has been asked before and I visited the VBNet website and ran the code to determine the operating system. My problem is I am running Windows Vista Home Edition. This code reports I am...
3
by: Giampaolo Rodola' | last post by:
Hi, I'd like to know if there's a way to determine which is the best buffer size to use when you have to send() and recv() some data over the network. I have an FTP server application which, on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.