如何使 Python 脚本成为 Windows 可执行文件的插件?

发布于 2024-10-07 17:47:22 字数 738 浏览 1 评论 0原文

我编写了一个小的 Python 脚本 wrapcl.py 脚本,它包装了我们的编译器二进制文件(cl.exe,Microsoft Visual Studio C++ 编译器)。然后,我创建了一个新的批处理文件 cl.bat,该文件使该 Python 脚本可访问,以便我可以像以前一样运行 cl,并且它会默默地调用我的包装器脚本,而不是真正的程序。无论如何,这是我的 cl.bat 批处理文件:

@python %~dp0\wrapcl.py %*

这工作得很好 - 除了一种情况:

我们有现有的脚本,可以执行类似

cl >NUL 2>&1 && GOTO CL

确定 Microsoft Visual Studio C++ 编译器是否可用的操作。如果 cl 实际上调用我的 cl.bat 批处理文件,则会中断,因为对 cl.bat 的调用永远不会返回。为此,我们必须使用call cl >NUL ...

有什么方法可以让我的 wrapcl.py Python 脚本对于调用者来说看起来就像 cl.exe 一样,这样我就可以避免触及需要 cl 的现有脚本&& foo 工作吗?

I wrote a little Python script wrapcl.py script which wraps our compiler binary (cl.exe, the Microsoft Visual Studio C++ compiler). I then created a new batch file cl.bat which makes that Python script accessible so that I can run cl as before and it will silently call my wrapper script instead of the real program. For what it's worth, here is my cl.bat batch file:

@python %~dp0\wrapcl.py %*

This works quite well - except in one case:

We have existing scripts which do something like

cl >NUL 2>&1 && GOTO CL

to determine whether the Microsoft Visual Studio C++ compiler is available. This breaks if cl actually calls my cl.bat batch file since the call to cl.bat never returns. We'd have to use call cl >NUL ... for that.

Is there any way I can make my wrapcl.py Python script look just like cl.exe for callers so that I can avoid touching our existing scripts which expect cl && foo to work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青巷忧颜 2024-10-14 17:47:22

一种可能性是使用 py2exe 将 python 代码编译为可执行文件。这是一个链接:
py2exe

One possibility is to compile your python code as an executable using py2exe. Here's a link:
py2exe

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文