Computer Hope

Software => Computer software => Topic started by: Bennieboj on October 15, 2011, 02:38:27 AM

Title: OS independant portability?
Post by: Bennieboj 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
Title: Re: OS independant portability?
Post by: Salmon Trout 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?


Title: Re: OS independant portability?
Post by: Salmon Trout 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?


Title: Re: OS independant portability?
Post by: BC_Programmer 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)



Title: Re: OS independant portability?
Post by: Geek-9pm 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.
Title: Re: OS independant portability?
Post by: Salmon Trout 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!
Title: Re: OS independant portability?
Post by: immental1200 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?
Title: Re: OS independant portability?
Post by: Salmon Trout on October 15, 2011, 03:12:07 PM
Solution found?


Quote
<script type="text/javascript">

see above

Title: Re: OS independant portability?
Post by: patio on October 15, 2011, 04:06:27 PM
Wow...
Title: Re: OS independant portability?
Post by: Geek-9pm 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 (http://www.zdnet.com/blog/bott/the-real-history-of-java-and-android-as-told-by-google/3924)
Hope the OP reads it. He may find the answer to his quest.
Title: Re: OS independant portability?
Post by: Salmon Trout 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/

(http://i124.photobucket.com/albums/p29/badoit/UserAgent.jpg)
Title: Re: OS independant portability?
Post by: Bennieboj 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.
Title: Re: OS independant portability?
Post by: Geek-9pm 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.
Title: Re: OS independant portability?
Post by: BC_Programmer on October 16, 2011, 06:13:47 PM
For example, Adobe Flash needs Java.
No it doesn't...
Title: Re: OS independant portability?
Post by: Geek-9pm 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?
Title: Re: OS independant portability?
Post by: Bennieboj on October 16, 2011, 11:20:14 PM
I also read something about Java Portable (Jportable, by PortableApps.com). (http://portableapps.com/apps/utilities/java_portable)
In fact I could run a .bat (on windows ofc) using the JRE/JDK on my stick. The same goes for linux/unix (a bash script), and mac also has bash, I suppose...
Like mentioned here (http://en.allexperts.com/q/Java-1046/portable-java.htm) in general, here (http://ubuntuforums.org/showthread.php?t=836040) and here  (http://ubuntuforums.org/showpost.php?p=5190521)for linux and here (http://portableapps.com/apps/utilities/java_portable) for windows.

In that way I should have java in my pocket. I'm only dependant on the shells (like msdos and Bourne Again SHell), but since those platforms always come with these there's no problem at all.

Now I just need to get it to work. I'll first write my program, then test the portable java stuff and then I'll come back to here =)
Title: Re: OS independant portability?
Post by: Geek-9pm on October 16, 2011, 11:30:49 PM
Good move. Java or some equilateral will be around for awhile.
You may have heard, Sun/Oracle tried to make part of Java Open Source. It was an attempt to get more people into Java.