Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: OS independant portability?  (Read 5929 times)

0 Members and 1 Guest are viewing this topic.

Bennieboj

    Topic Starter


    Rookie

  • time flies, ur the pilot
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 7
OS independant portability?
« on: October 15, 2011, 02:38:27 AM »
Hi everyone,

I've got a question for you: Is it possible to make a program that detects the OS it's running on, portably and platform independant?
Atm I'm only talking about Windows, Mac and Linux...
What I basically mean is, can I have my tiny source code (.c, .py, .....) and compile it so that it'll work on every OS?
I already tought about Java, but if java isn't installed the program won't run....
Is there another way so that I can run my code on every OS I mentioned?
I only need to know on what OS I am running, after that it's peanuts, simply run a program specifically for that OS...

Can you guys help me with this?

Thanks in advance,

Bennieboj

Salmon Trout

  • Guest
Re: OS independant portability?
« Reply #1 on: October 15, 2011, 03:48:44 AM »
Yes it is possible in certain limited cases, and here's some reading to start you off...

http://en.wikipedia.org/wiki/Cross-platform

I can imagine some problems with compiled code, e.g. Linux won't run Windows .exes natively and Windows won't run compiled Linux programs, but with scripted languages such as Python, Java, etc, you are in with a chance as long as the appropriate script interpreter is installed on the target machines. Here's a clue as to how easy it might be: you see lots of compiled apps for download where you can choose which platform you want to use (win32, win64, Linux, MacOS etc) but not very many where you don't need to do that.

What sort of app are you talking about?



Salmon Trout

  • Guest
Re: OS independant portability?
« Reply #2 on: October 15, 2011, 03:57:45 AM »
I only need to know on what OS I am running, after that it's peanuts, simply run a program specifically for that OS...

Do you mean you are compile a version for every platform, and package them all together and then run some kind of platform-independent loader which detects the OS and selects the correct version? If so, why? Why can't you let the user decide which version they want?



BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: OS independant portability?
« Reply #3 on: October 15, 2011, 10:09:47 AM »
The short answer is basically no.

when you compile something, it builds in static code that is platform dependent. For example, with a .c program, the c standard library that is linked in is platform-dependent; that is, you aren't going to have the "same" standard library when you compile a C program on windows as you will when you compile on Linux. Now, to be clear, it will look and act the same, but I mean the standard library is basically a "standard" way for you to access the platform dependent functionality; for printf(), for example, with windows it will eventually call the WriteFile/WriteFileEx() or some equivalent to write the data to the standard output. With Linux, it will eventually end up calling the appropriate syscall.

It's not possible to somehow include both and then include a check when it starts because that would imply the use of function pointers for every single Standard library function, not to mention it would nearly double the size of the executable.

This extends to the compiled form of most script languages, which usually just embed a script interpreter that has to run on the desired platform, thus being limited to the aforementioned issues.

Of course with a language such as Java or .NET that runs in a Virtual Machine, this is not really much of an issue; the same executable for many .NET applications, if written for the case, can run just fine on either Linux (via Mono) or on a windows machine, and java is of course a living example of this. I  think if the machine doesn't have java and your application can't run you have to think hard about whether the person using said machine really wants to run your program at all.

Thing is, people have already thought "it would be nice to have one program I could compile and run that compiled program on a variety of machines" and the result was java and various other VM based languages that you have essentially discarded, essentially because they need an installed VM. Of course they do. This is a case of "wanting your cake and eating it too" in that you want to advantages that running as VM bytecode gives you (platform independence) without the costs (having to have the VM installed)



I was trying to dereference Null Pointers before it was cool.

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: OS independant portability?
« Reply #4 on: October 15, 2011, 01:25:01 PM »
Quote
I already tought about Java, but if Java isn't installed the program won't run...
The OP has already passed up a important work that was created for exactly for what he wants to do. Does he have any idea of how much work went into perfecting Java?

And yes, there  is new work that solves the problem. But it is not what the OP wants. Still, if he wants to re-invent the wheel, so be it. Just maybe he will find a concept nobody else has ever tried.

Salmon Trout

  • Guest
Re: OS independant portability?
« Reply #5 on: October 15, 2011, 01:51:31 PM »
The OP has already passed up a important work that was created for exactly for what he wants to do. Does he have any idea of how much work went into perfecting Java?

The ungrateful wretch!

immental1200

  • Guest
Re: OS independant portability?
« Reply #6 on: October 15, 2011, 03:04:58 PM »
http://www.thismachine.info/

That is able to tell you details about the current machine ... it runs through a web-browser (so runs on any platform)

Solution found?

Salmon Trout

  • Guest
Re: OS independant portability?
« Reply #7 on: October 15, 2011, 03:12:07 PM »
Solution found?


Quote
<script type="text/javascript">

see above


patio

  • Moderator


  • Genius
  • Maud' Dib
  • Thanked: 1769
    • Yes
  • Experience: Beginner
  • OS: Windows 7
Re: OS independant portability?
« Reply #8 on: October 15, 2011, 04:06:27 PM »
Wow...
" Anyone who goes to a psychiatrist should have his head examined. "

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: OS independant portability?
« Reply #9 on: October 15, 2011, 04:48:51 PM »
http://www.thismachine.info/

That is able to tell you details about the current machine ... it runs through a web-browser (so runs on any platform)

Solution found?
Yes.. I alluded to that. If you bring in the clouds, cross-platform is no longer an issue. If a computer has a browser, it can run cloud applications. They are actually doing that with i Phone  and Android Aps. No that a Android Applications runs on an i Phone, but mosts Aps have  some cross-platform twin in the clouds.
And Java is there too.
The real history of Java and Android, as told by Google | ZDNe
Hope the OP reads it. He may find the answer to his quest.

Salmon Trout

  • Guest
Re: OS independant portability?
« Reply #10 on: October 15, 2011, 05:44:23 PM »
http://www.thismachine.info/

That is able to tell you details about the current machine ... it runs through a web-browser (so runs on any platform)

Solution found?

Solution most definitely NOT found. Nothing runs on your "platform". The website reads the browser's user agent string, which can be spoofed anyway.

Just like this one:

http://whatsmyuseragent.com/



Bennieboj

    Topic Starter


    Rookie

  • time flies, ur the pilot
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 7
Re: OS independant portability?
« Reply #11 on: October 16, 2011, 05:05:29 AM »
So basically, as BC_programmer said, the answer is no, I can't eat the cake and have it too =)
Thanks to all of you for your time and for the interesting links!

I'll just use java and assume that java is installed on the platform, that'll be the easiest solution I guess.

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: OS independant portability?
« Reply #12 on: October 16, 2011, 11:59:44 AM »
So basically, as BC_programmer said, the answer is no, I can't eat the cake and have it too =)
Thanks to all of you for your time and for the interesting links!

I'll just use java and assume that java is installed on the platform, that'll be the easiest solution I guess.
Yes, you can go that way. Most users wail have Java.
When people install programs developed with Microsoft tools, the may have to install a dot NET run time modules. And with many -non-Microsoft development you have to have Java. For example, Adobe Flash needs Java. So users have come to expect that some programs or add-ons require a run-time library.

About browsers. Most, if not all, browsers run javascript. So if you limit yurself to HTML, you can use javascript. If course, it never is an EXE file.

And javascript ain't Java.

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: OS independant portability?
« Reply #13 on: October 16, 2011, 06:13:47 PM »
For example, Adobe Flash needs Java.
No it doesn't...
I was trying to dereference Null Pointers before it was cool.

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: OS independant portability?
« Reply #14 on: October 16, 2011, 07:30:59 PM »
Quote from: Geek-9pm on Today at 11:59:44 AM
    For example, Adobe Flash needs Java.

No it doesn't...
What? Then tell what does. I updated something and it said my Java also needed an update. What was it that did that?