将 bash 脚本编译为 Windows 可执行文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7033865/
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 17:49:09  来源:igfitidea点击:

Compiling a bash script into a windows executable

windowsbashcompilation

提问by Daisetsu

I have a script which was origionally made for Linux, but adapted to run with Cygwin in windows, and if you already have the executables (sh, cp, mv, etc.) then you can run it without Cygwin. The only problem is that the script also uses a few hundred (yes hundreds) of other executables. Is there any way I can compile this script into a regular executable and pack these other supporting files in as resources?

我有一个最初为 Linux 制作的脚本,但适用于在 Windows 中与 Cygwin 一起运行,如果您已经拥有可执行文件(sh、cp、mv 等),那么您可以在没有 Cygwin 的情况下运行它。唯一的问题是该脚本还使用了数百个(是数百个)其他可执行文件。有什么方法可以将此脚本编译为常规可执行文件并将这些其他支持文件打包为资源?

The script is ~1600 lines long which is probably too long to confortably re-implement by hand in C++. I am looking to compile the script into something which windows can execute without having to make edits to the path to include a bunch of third party executables. A way to contain all this.

该脚本长约 1600 行,这可能太长而无法在 C++ 中手动重新实现。我希望将脚本编译成 Windows 可以执行的内容,而无需编辑路径以包含一堆第三方可执行文件。一种包含所有这些的方法。

回答by Keith Thompson

I doubt that the solution you have in mind is feasible.

我怀疑您想到的解决方案是否可行。

Instead, I'd modify the script so that the first thing it does is figure out where all those hundreds of executables are. Then either set $PATHappropriately, or invoke each one by its full pathname.

相反,我会修改脚本,以便它做的第一件事就是找出所有数百个可执行文件的位置。然后$PATH适当地设置,或通过其完整路径名调用每个。

Or you can have an installer that installs the executables in a specified or user-chosen location, then re-generates the script (from an input file) so it knows where the executables are. Ship with the-script.in, then have the installer perform textual substitutions to generate the-scriptfrom the-script.in.

或者,您可以让安装程序将可执行文件安装在指定的或用户选择的位置,然后重新生成脚本(从输入文件),以便知道可执行文件的位置。随附the-script.in,然后让安装程序执行文本替换以the-scriptthe-script.in.

回答by H_7

I point out:

我指出:

RPMand SHC

RPMSHC

as a possible solution for your problem. Maybe this tools helps you to do the job.

作为您问题的可能解决方案。也许这个工具可以帮助你完成这项工作。

回答by Erico Schuch

Using SHC to Cygwin is possible to compile bash to exe Ok. Realy old, but I was looking for it and decide to do my self and make it public. http://goo.gl/M1NSY

使用 SHC 到 Cygwin 可以将 bash 编译为 exe Ok。真的很旧,但我一直在寻找它并决定做我自己并公开它。 http://goo.gl/M1NSY

回答by Camilo Martin

Use ports of the required utils and use some application virtualization tool to package it all up. Cameyois a free one. Forget Cygwin, that thing is huuuge :)

使用所需工具的端口并使用一些应用程序虚拟化工具将其全部打包。Cameyo是免费的。忘记 Cygwin,那是 huuuge :)