Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can we run a .bat file on Mac OS X?

Has anyone done it?

share|improve this question

migrated from stackoverflow.com Dec 6 '10 at 22:28

This question came from our site for professional and enthusiast programmers.

2  
You would need to run DOS or Windows in a VM to do this e.g. using Parallels, VMware Fusion or Virtual Box. –  Paul R Dec 6 '10 at 22:23
    
I disagree that this off topic it's about batch scripting which is programming and he's asking to run code from one language on a another machine. –  Preet Sangha Dec 6 '10 at 22:25
    
I don't think that's off-topic - it could be that running .bat files on Mac is part of some programming task - akin to asking if there is way to do DirectX on Mac... –  EFraim Dec 6 '10 at 22:27
    
DosBox is much lighter than Parallels/VMWare/Virtual Box. –  user31752 Dec 6 '10 at 22:33
2  
Do you need to run .bat files specifically, or do you just need to write a script on a Mac? –  Sasha Chedygov Dec 6 '10 at 23:00

4 Answers 4

The equivalent to "batch files" on OS X are "shell scripts" (since OS X is derived from Unix). These are written in much the same way, as a text file with a list of commands to run. For example:

#!/bin/sh

echo "This is a shell script!"
cd ~/tmp
if [ -f "foo.txt" ]; then
    echo "foo.txt exists"
fi
share|improve this answer
3  
bash and batch are similar, but have very distinct differences to those who are not very literate in the ways of programming. It is not that easy for everyone to translate between the two so this really doesn't answer his question at all. –  MaQleod Dec 6 '10 at 22:52

It depends on how complicated your requirements are. The fact that you are even asking this questions implies that you do not have extensive knowledge of Mac so you'll probably do something simple. If you're not a unix geek there'll be a steep learning curve with shell scripts. Have a look at automator and see if it will do what you want. You can read about it on Wikipedia or type "Automator" into that help thingie you find on the mac menubar.

share|improve this answer

Mac OSX is BSD based no? You may be able to use different shell like/emulator like doscmd

share|improve this answer

For what purpose? Hard to give a good answer without more context.

.command files are similar to .bat files. Of course, the commands in whatever file you're using have to be valid for Mac (can't use a Windows .bat file with Windows command, of course).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.