Opening .bat files

Joined
Jul 5, 2010
Messages
6
Reaction score
0
Points
1
How would I go about opening a .bat file meant for a Windows computer on a Mac? I know I would have to edit it/rewrite some of it, but what exactly do I edit?
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
16,033
Reaction score
2,438
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Without knowing what the .BAT file actually contains, it's hard for us to know what you have to change..

Regards
 

vansmith


Retired Staff
Joined
Oct 19, 2008
Messages
19,966
Reaction score
606
Points
113
Location
Queensland
Your Mac's Specs
Too many devices to list
You're going to have to change 99% of it, if not everything. OS X and Windows use two very different approaches to CLI scripting. If you post what you have, perhaps I (we) can help you rewrite it.
 
OP
B
Joined
Jul 5, 2010
Messages
6
Reaction score
0
Points
1
My father has helped with .bat files before, and I don't think he changed all that much of them. Anyway, this is the text in it.


@echo off
COLOR 09
title SilabGarza Client v3.6
cd .\FILES\
java -Xmx1000m -cp .;Theme.jar Bot 0 0 lowmem members 32
pause

For the future, it would also be helpful to know how to rewrite them myself, without having to resort to posting on the forum :D

P.S. When my father helped rewrite them, I am 99% sure he used Terminal. I'm not sure how he did that though, so any help would be appreciated :)
 
Joined
Oct 1, 2007
Messages
7,163
Reaction score
275
Points
83
Location
UK
Your Mac's Specs
Mac Mini i5 (2014 High Sierra), iPhone X, Apple Watch, iPad Pro 12.9, AppleTV (4)
BAT files are just text files. They contain script commands that Windows can interpret.

They can be edited on most platforms in any plain text editor (on OSX try TextEdit or Text Wrangler).

As to your question what to change . . . that's near impossible to answer. The file you've posted above appears to invoke a precompiled java app using a set of parameters.

I'd hazard a guess that it's a bespoke app of some kind.

You can change the commands by just typing/overtyping. But asking what to change is a nearly impossible question to answer from the info you've supplied I'm afraid.

You'd need to state what you are trying to do, what it does now and what it needs to do, but even then what you're asking is somewhat 'tricky'.

What's the end result you want to achieve? Are you trying to run this java app on Mac?
 
OP
B
Joined
Jul 5, 2010
Messages
6
Reaction score
0
Points
1
BAT files are just text files. They contain script commands that Windows can interpret.

They can be edited on most platforms in any plain text editor (on OSX try TextEdit or Text Wrangler).

As to your question what to change . . . that's near impossible to answer. The file you've posted above appears to invoke a precompiled java app using a set of parameters.

I'd hazard a guess that it's a bespoke app of some kind.

You can change the commands by just typing/overtyping. But asking what to change is a nearly impossible question to answer from the info you've supplied I'm afraid.

You'd need to state what you are trying to do, what it does now and what it needs to do, but even then what you're asking is somewhat 'tricky'.

What's the end result you want to achieve? Are you trying to run this java app on Mac?


Yes, I'm trying to run the Java file on my Mac. If you need any other information, I'm afraid I don't know enough about this to help. All I know is that I have to rewrite it to make it run :)
 

vansmith


Retired Staff
Joined
Oct 19, 2008
Messages
19,966
Reaction score
606
Points
113
Location
Queensland
Your Mac's Specs
Too many devices to list
Try the following:
Code:
#!/bin/sh
cd <location> (replace with the location of the jar)
java -Xmx1000m -cp .;Theme.jar Bot 0 0 lowmem members 32
If you still need the pause at the end, take a look at this.
 
OP
B
Joined
Jul 5, 2010
Messages
6
Reaction score
0
Points
1
Try the following:
Code:
#!/bin/sh
cd <location> (replace with the location of the jar)
java -Xmx1000m -cp .;Theme.jar Bot 0 0 lowmem members 32
If you still need the pause at the end, take a look at this.

By the "location of the jar" do you mean something like /Users/Name/Desktop/SilGar\ v3.6/FILES? I tried doing that, then I opened the BAT file in Terminal, and then it said:

Code:
/Users/danny/Desktop/SilGar v3.6/Run.bat: line 3: Theme.jar: command not found

And then below that, it says what I told the pause prompt to say.
 

vansmith


Retired Staff
Joined
Oct 19, 2008
Messages
19,966
Reaction score
606
Points
113
Location
Queensland
Your Mac's Specs
Too many devices to list
By the "location of the jar" do you mean something like /Users/Name/Desktop/SilGar\ v3.6/FILES? I tried doing that, then I opened the BAT file in Terminal, and then it said:

Code:
/Users/danny/Desktop/SilGar v3.6/Run.bat: line 3: Theme.jar: command not found

And then below that, it says what I told the pause prompt to say.
Hold on, we're going to start over. First off, if Jar Launcher works for you, go with it. It may not work because it looks as if you're passing parameters to the jar file. Otherwise, let's start again.

First, open up an editor and paste in the following:
Code:
#!/bin/sh
java -Xmx1000m -cp .;<location>/Theme.jar Bot 0 0 lowmem members 32
Replace <location> with the location of the jar. So, using your example, if the jar file was in /Users/Name/Desktop/SilGar\ v3.6/FILES, make sure the contents of this file read as such:
Code:
#!/bin/sh
java -Xmx1000m -cp .;/Users/Name/Desktop/SilGar\ v3.6/FILES/Theme.jar Bot 0 0 lowmem members 32
Save that with the extension .sh. Make sure to save it as plain text (if you're using TextEdit, go to Format > Make Plain Text before saving). Now, open up a Terminal and type the following:
Code:
chmod +x <location of sh file>/<sh file>
For example:
Code:
chmod +x /Users/Name/jar_launcher.sh
Once that is done, your script is ready to execute. If you want to execute it, simply type the directory and name of the script at the Terminal prompt. For example:
Code:
/Users/Name/jar_launcher.sh
 
OP
B
Joined
Jul 5, 2010
Messages
6
Reaction score
0
Points
1
Hold on, we're going to start over. First off, if Jar Launcher works for you, go with it. It may not work because it looks as if you're passing parameters to the jar file. Otherwise, let's start again.

First, open up an editor and paste in the following:
Code:
#!/bin/sh
java -Xmx1000m -cp .;<location>/Theme.jar Bot 0 0 lowmem members 32
Replace <location> with the location of the jar. So, using your example, if the jar file was in /Users/Name/Desktop/SilGar\ v3.6/FILES, make sure the contents of this file read as such:
Code:
#!/bin/sh
java -Xmx1000m -cp .;/Users/Name/Desktop/SilGar\ v3.6/FILES/Theme.jar Bot 0 0 lowmem members 32
Save that with the extension .sh. Make sure to save it as plain text (if you're using TextEdit, go to Format > Make Plain Text before saving). Now, open up a Terminal and type the following:
Code:
chmod +x <location of sh file>/<sh file>
For example:
Code:
chmod +x /Users/Name/jar_launcher.sh
Once that is done, your script is ready to execute. If you want to execute it, simply type the directory and name of the script at the Terminal prompt. For example:
Code:
/Users/Name/jar_launcher.sh

What I tried did not work, so just to recap:

1. Edit the run.bat file to #!/bin/sh
java -Xmx1000m -cp .;<location> Bot 0 0 lowmem members 32, and save it with the extension .sh
2. Open terminal and enter chmod +x /Users/danny/Desktop/SilGar\ v3.6/Run.sh
3. Hit enter

Sorry for being so uneducated in terms of programming :p
 
Joined
Jan 12, 2009
Messages
1,096
Reaction score
19
Points
38
Location
Prague, Czech Republic
Your Mac's Specs
2,4Ghz 15" unibody
Nice post lol :D

it's two commands:
1. "java -Xmx1000m -cp ."
-cp that will do a search for a class in the current dir, but why not just pass in the single class?
-Xmx100M is a setting for the heap size, what exactly are you trying to run lol? :D

2. "Theme.jar Bot 0 0 lowmem members 32"
you can retype this as:
java -jar Theme.jar Bot 0 0 lowmem members 32

I would edit the file in the following way:
java -Xmx1000m -cp .
java -jar Theme.jar Bot 0 0 lowmem members 32

save it in the same location as the original .bat, add execute permissions as described above

and dude, when some1 used <> it meant you needed to substitute that for the correct path, not write <location> in your script :)
 

vansmith


Retired Staff
Joined
Oct 19, 2008
Messages
19,966
Reaction score
606
Points
113
Location
Queensland
Your Mac's Specs
Too many devices to list
Reading this might be useful. As it notes, if you put a semi-colon between two commands, it will execute the second regardless of whether there was an error with the first. If you put two ampersands between the commands, it will execute the second only if the first was successful.

So, you could put those two java commands on one line if you wanted:
Code:
java -Xmx1000m -cp . ; java -jar Theme.jar Bot 0 0 lowmem members 32
or
Code:
java -Xmx1000m -cp . && java -jar Theme.jar Bot 0 0 lowmem members 32
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top