views:

174

answers:

8

I'm looking for a way to make a dual executable file for Windows/Mac. That is, I can execute the file in either OS and it would run some piece of code that I want for that OS. This code can be either a script or (preferably) natively compiled code, but it needs to run on the vanilla OS without needing any extra tools or libraries installed. The other requirement is it needs to be a single file.

Anyone know of a way to do this or is this even possible?

+1  A: 

In a script it's all ok, but in a compiled code it will be impossible, because the WIndows executable(exe) is different from the Mac executables(bin) that are different from the Linux executables(whatever you want).

Nathan Campos
+1  A: 

As long as you use a cross-platform language such as Java you can run it on either OS. Native code won't be executable however.

Kyle Trauberman
+1: Executable JAR's do this.
S.Lott
java is not installed by default on all platforms
Adrien Plisson
true, but why is that a problem? its a fairly simple thing to install, and is common enough that it is a reasonable requirement. - That said, I did re-read the question and it does say that the OP is looking for something native to the vanilla OS, and java does not fit that profile.
Kyle Trauberman
+1  A: 

There is nothing similar between the two. No program or script in any language would run exactly the same on both machines without other requirements such as a bash interpreter for Windows for example.

Deverill
+1  A: 

Mono or Java can be installed on a Mac and run programs designed to be cross platform. Without this kind of special library to support multiple platforms there is no common denominator and no way to run the same app on both.

Snarfblam
+8  A: 

The only way I can see this working is having extra tools installed:

  • Scripts: The command parsers are extremely different between the Mac (bash shell) and Windows (which has 2: PowerShell and the original, don't know its technical name). You'd either have to have Services for Unix/Cygwin/Insert-other-UNIXy-Environment here installed on the Windows box, or use something like perl or another scripting language. In either event, at least the Windows box, and possibly the Mac, need additional out-of-box tools.
  • Executables: The only way you can pull this off is to use Java, .NET/Mono or some other cross-platform bytecode-based virtual machine environment. Hence, you are still dependent on tools which are not in-box. (IIRC, Java doesn't ship with Windows, and Mono doesn't ship with Mac.)
  • Other Issues: The biggest issue you'll run into after dealing with the tool dependency is that paths are identified differently on both systems. Understanding that Mac paths are generally Unix-style paths (although I believe "old-school" Mac colon-separated paths are still valid). You'll also have to deal with different file locations and default locations based on both environments. This will be a pain.

Now, if you can get away with using a cross-compile instead of binary compatibility, you may have an answer in a tool called RealBasic. It was originally Mac-based, but there are versions for Windows and Linux as well. I used to play around with it in the early part of this decade, and it was pretty neat, but not something I ever used professionally. This will, if you're careful, allow you to write the code once, and compile the very same code as native Mac, Linux and Windows applications.

John Rudy
Windows has two shells, the old cmd shell (probably got another name) which isn't a lot of use to anyone and Powershell which is very good indeed (-: Its also possible to run vbscript or jscript under windows separately from the command shells. Still not a lot of use in solving the problem though!
Murph
I forgot about Powershell; good call! I'll edit accordingly.
John Rudy
A: 

You might want to check out Realbasic. It is a VB clone language with an IDE. It will build executables for Windows, Mac and Linux. realbasic.com

Dave
A: 

You might consider looking at StarKits which work with Tcl/Tk.

Asif
+1  A: 

Not exactly what you want, but maybe noteworthy:

You can use Cocotron to compile programs written in Obj-C using Cocoa for Windows. Works pretty well! This won't give you one executable for Mac and Windows, but one for the Mac and one for Windows.

Pascal