M BUZZ CRAZE NEWS
// news

How to launch a .bat

By Jessica Wood

I'm running Mac OS X El Capitan and I'm not quite sure how to launch a .bat extension anymore. I used to be able to just do it right away, but now it asks me to select an application to use to open it up. I don't know which to use. Please help.

edit: it used to work just fine and open in command center even though it has a .bat extension. It changed when I switched to El Capitan

edit 2:

java -Xmx3G -Xms2G -jar Tekkit.jar noggin
pause
11

3 Answers

[updated: 2016-05-18] Missing the -jar parameter. Tks for pointing that out @barlop.

[updated: 2016-05-17] Disambiguation edits/improvements.

Please note: you do not need to download WINE [edit]just[/edit] to run a batch script. In fact, do not [edit]try to run batch, instead convert it to the equivalent shell script for your system[/edit].

As pointed out, .bat is script run by Microsoft's CLI. For Mac, I believe you need something along these lines ([edit]I've dug around and found Minecraft is Java and so[/edit]):

!# /bin/sh
java -jar ~/Library/Application Support/minecraft/bin/minecraft.jar
# Please note the above path is based on internet sources. Also, I'm
# not very Java knowledgeable but maybe someone can add/edit where needed.

Save it as a .sh file (and if needed chmod it to ug+x). Then place it wherever you wanted the shortcut to go (or in something akin to /usr/bin/ if you want it available system-wide).

Obviously, as others have said, without seeing the contents of the batch file, nobody here can give you a precise sh translation.

10

.bat files are native to Windows, not Mac OS.

In order to launch a .bat file, you will need to use something on the mac that launches windows executables, such as wine, etc.

Alternatively, find a mac version of the program you're launching. Its likely have its own kind of scripting in the form of a bash or ksh file. Batch (.bat, .cmd) files are scripts too, but written for windows.)

4

Here is some basic Unix info. Not many "El Capitan"-specific details are provided, but they should not be needed to get things to work. (I understand that an upgrade to "El Capitan" broke things. Perhaps it changed what is in your path, or altered some permissions. Following are details on how to make things work.

In DOS, a batch file is a text file that ends with ".BAT" (case-insensitive, so ".bat" would also work). Microsoft Windows follows the DOS tradition. Each line in the batch file is a command to be run from the command interpreter.

In Unix, including Mac OS X, a proper "shell script" file should have a proper header, and have proper permissions. Then, after the header, each line in the batch file is a command to be run from the command interpreter.

Notice that those descriptions are mostly the same. Mainly, most of the script file is just a list of commands to run. Commands which are the same between DOS and Unix, like "cd ..", or the names of executable files within the PATH, may work equally well with both types of files.

If you had a Unix script file that said:
#!/bin/sh @Echo Off echo hello cd . more < readme.txt

Then the first line of the file would cause a harmless error in DOS/Windows, the second line of the file would cause a harmelss error message in Unix, and the rest of the file could work identically in both environments.

Whether this will actually work well for you, or not, may largely depend on what commands you use. For instance, "cd bin" can work well with both environments, but DOS/Windows use a backslash as a directory separator while Unix uses a forward slash. So some commands may not work well.

The best way for us to predict how well your particular batch file would work well, or not, is if we knew the contents of the batch file. Hence why barlop's comment asked about the contents of the batch file.

Regarding your question (from one of your comments) on which extension to use: In DOS/Windows, the answer is ".BAT" (any amount of lowercase is fine, so ".bat" is okay too.) In Unix, the most common standards are "none" (no extension), or ".sh". However, in Unix, the extension really doesn't matter significantly. What matters is whether the file has the necessary permissions, and possibly whether it starts with the appropriate header. So make sure those things are right. (The header is the first line shown in my prior sample. The permissions can be set using "chmod a+x filename.bat" but, of course, specify the actual location of the filename.) When you run the file in Unix, make sure to specify the entire filename of the script file, including the ".bat" extension. (If you don't like doing that, simply make a symlink, having a symlink named "gonow" point to "gonow.bat" (or whatever is approrpriate).

The other way to do this in Unix is to run the .BAT file from within another piece of software which is DOS-like. e.g., COMMAND.COM within Wine, or perhaps CMD.EXE within WINE, or other Wine variants like Crossover, or other software like DOSBox or DOSemu. If you do so use this software that is designed to work quite like DOS, then that software may be able to run the file without requiring that you specify the ".bat" extension.

Another alternative may be to simply use a Shell Script file that runs Java (since the contents of the batch file, mentioned elsewhere, show Java being run), and ignore trying to use a file that ends with the ".bat" extension. (So it wouldn't be a .bat file, but would be a shell script or a symbolic link.)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy