是否有适用于 UNIX 的“Windows 批处理文件”模拟器/解释器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5698184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:40:34  来源:igfitidea点击:

Is there the "Windows Batch file" emulator/interpreter for UNIX?

windowsunit-testingmacosunixbatch-file

提问by kaorukobo

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

我可以在 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.

我正在寻找在 UNIX 上运行 Windows 批处理文件的解释器,例如 'bash' 用于 bash 脚本,'csh' 用于 csh 脚本,所以 'XXX' 用于 Windows 批处理文件。

I am developing a Java application.

我正在开发一个 Java 应用程序。

  • 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.
  • 开发环境在 Mac OS X 上
  • 但目标(主要执行)环境在 Windows 上。
  • 该应用程序使用 Windows 批处理文件和可执行文件。
    • 它生成 *.bat 来运行存根程序 (*.exe)。
  • 所以我想编写单元测试并准备存根程序(*.exe 作为 bash 脚本),
  • 并希望在 Mac OS X 上运行它 - 而不是 Windows。
    • 但是,这并不意味着我要执行(模拟)Windows 二进制文件 (*.exe)...我只想启动 *.bat 并让它调用由 sh/perl/ruby 制作的测试存根 *.exe。

...Any ideas?

...有任何想法吗?

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

(相关) 如何从 UNIX-AIX 执行 Windows 批处理文件?

采纳答案by sehe

cmd.exe is rated NSFW in my area code

cmd.exe 在我的区号中被评为 NSFW

On windows look at PowerShell

在 Windows 上查看PowerShell

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

如果您坚持,请在 linux、Solaris、BSD 等上使用Wine。它带有 cmd.exe :)

Wikipedia on Wine

关于葡萄酒的维基百科

MacOSX support:

MacOSX 支持:

回答by paxdiablo

No, there isn't such a beast. And, if there isa 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, muchharder.

虽然创建批处理文件解释器的工作量中等(特别是如果您没有使用 的每个功能cmd.exe),但运行可执行文件困难得多。

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.

我将研究启动一个干净的 Windows 虚拟机并在那里在 Windows 下运行您的应用程序的解决方案。您也可以像 Windows 程序一样轻松地进行单元测试,而不必担心从 OSX 驱动 VM。

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).

然后您唯一需要关心的是如何将结果从 Windows VM 返回到 OSX。通过网络存储(共享驱动器或 NFS 或类似的东西)这应该是可行的(虽然笨拙)。

回答by Pandan

or, download minimalistic MS Windows image from MS.

或者,从 MS 下载简约的 MS Windows 映像。

https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/

https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/