在Windows中使用lua os.execute启动没有CMD刷新的程序 [英] Use lua os.execute in windows to launch a program with out a flash of CMD

查看:108
本文介绍了在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不允许使用依赖于操作系统的本机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天全站免登陆