在 windows 中使用 lua os.execute 来启动一个程序,不需要一闪而过的 CMD [英] Use lua os.execute in windows to launch a program with out a flash of CMD

查看:75
本文介绍了在 windows 中使用 lua os.execute 来启动一个程序,不需要一闪而过的 CMD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很高兴使用 Lua 在 windows 系统中启动一个程序

I am happily launching a program in a windows system from Lua using

strProgram = '"C:\Program Files\Ps Pad\PSPad.exe"'
strCmd = 'start "" '..strProgram
os.execute(strCmd)

这工作正常,启动程序和脚本完成.它如何闪现一个命令窗口几分之一秒,有没有人有办法从 Lua 启动程序.

This works correctly, launching the program and the script finishing. How ever it flashes up a command window for a fraction of a second, does any one have a way from Lua to launch a program.

推荐答案

Lua 的 os.execute 命令基于 C 标准库shell"函数.在 Windows 中,此函数将始终创建一个命令窗口,并且它始终会停止您当前的进程,直到该窗口结束.后者也发生在 Linux 中.

Lua's os.execute command is based on the C standard library "shell" function. In Windows, this function will always create a command window, and it will always halt your current process until the window finishes. The latter also happens in Linux.

最终没有办法解决这个问题.不是通过 Lua 标准 API.由于 Lua 需要轻量级和平台无关性,API 不允许使用依赖于 OS 的原生 API.

There is ultimately no way around this. Not through the Lua standard API. Because Lua needs to be light-weight and platform independent, the API is not allowed to use OS-dependent native APIs.

最好的办法是使用 Lua Ex-Api 模块.它实际上是废弃软件,您可能需要修补一些编译器问题(我猜 Windows 端口不是他们的首要任务).但这是产生进程的一种相当好的方式.您可以选择等到它自己完成,或者让它们并行运行.并且它不会抛出命令提示符窗口,除非应用程序本身使用一个.

Your best bet would be to use the Lua Ex-Api module. It is effectively abandonware, and you may need to patch up a few compiler issues (I'm guessing the Windows port wasn't their first priority). But it is a reasonably good way to spawn processes. You can choose to wait until it finishes yourself, or let them run in parallel. And it won't throw up a command prompt window, unless the application itself uses one.

这篇关于在 windows 中使用 lua os.execute 来启动一个程序,不需要一闪而过的 CMD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆