9

Can I run the batch file on UNIX? (Linux / Mac OS X)

I am looking for the interpreter to run the Windows Batch file on UNIX, like 'bash' for bash script, 'csh' for csh script, so 'XXX' for windows batch file.

I am developing a Java application.

  • Development environment is on Mac OS X
  • but target(primary executed) environment is on Windows.
  • The applicaiton uses Windows batch file & executable.
    • it generates *.bat to run the stub program (*.exe).
  • So I want to write Unit-tests and prepare the stub program (*.exe as bash script),
  • and want to run it on Mac OS X - not Windows.
    • but, it does not mean that I want to execute (emulate) Windows binary (*.exe)... I only want to launch *.bat and let it to invoke test stub *.exe made with sh/perl/ruby.

...Any ideas?

(Related to) how i can execute windows batch file from UNIX-AIX?

Community
  • 1
  • 1
kaorukobo
  • 2,223
  • 2
  • 22
  • 29
  • 1
    Honestly, you probably do not need to test your .bat files within an emulator. Most .bat are so straightforward that there is no need to regularily test the output. How complicated is the script that you feel the need to test it? – Sled Apr 18 '11 at 04:21
  • It's often the case that there are some hacks up in management who want "code coverage" without knowing what it is for your application. – Noufal Ibrahim Apr 18 '11 at 10:59
  • I generates \*.bat with template engine, so I want to test that the result (batch file's content) correctly invoke the stub program. – kaorukobo Apr 18 '11 at 11:01
  • things are never this complicated if you do your application using one language. – kurumi Apr 18 '11 at 11:03

2 Answers2

5

cmd.exe is rated NSFW in my area code

On windows look at PowerShell

If you insist, use Wine on linux, Solaris, BSD etc. It comes with cmd.exe :)

Wikipedia on Wine

MacOSX support:

sehe
  • 374,641
  • 47
  • 450
  • 633
1

No, there isn't such a beast. And, if there is a god, there never will be :-)

While the effort to create a batch file interpreter is moderate to high (especially if you're not using every single feature of cmd.exe), running the executable is so much, much harder.

I would be investigating a solution of starting up a clean Windows virtual machine and running your application under Windows there. You could easily do your unit tests as Windows programs as well so as not to have to worry about driving the VM from OSX.

The only thing you then need to concern yourself with is how to get the results back to OSX from the Windows VM. That should be doable (though kludgy) via network storage (shared drives or NFS or something similar).

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • There was a `cmd` compiled for SFU (now SUA), though, so it *is* possible to get it running in a POSIX environment, if you have the source ;-) – Joey Apr 18 '11 at 07:41
  • Thanks, that's one of the best realistic ways :) Ah, if there is a god, I wish to work with a new powerbook and much more 2GB RAM... (;o;) – kaorukobo Apr 18 '11 at 10:53
  • I second this. You should really test your application in a test VM rather than on an emulated windows command line interpreter (which will mostly probably have behaviour different from the original line). – Noufal Ibrahim Apr 18 '11 at 11:00
  • @noufal-ibrahim Of course, the testing in Windows host is required. But it's much stress to do many running & fixing cycle on other host. So I want to finish almost fixes on my machine, then put the code on real environment. (then, of course, do more a bit fixes on it.) – kaorukobo Apr 18 '11 at 11:11