执行外部应用程序并退出(Execute external application and exit)

编程入门 行业动态 更新时间:2024-10-24 01:56:21
执行外部应用程序并退出(Execute external application and exit)

我在win7 x64上运行ActiveState perl 5。 该解决方案不一定是跨平台的。

我正在尝试使用Perl脚本为另一个应用程序构建一个有点复杂且可变的命令行参数字符串。 然后我想使用参数字符串执行该外部应用程序,同时也立即退出Perl脚本。

这个想法是创建快捷方式图标,它运行带有不同参数的Perl脚本,它应该生成适当的命令行,产生外部应用程序(为其提供适当的参数),然后立即离开。

我似乎无法找到任何方法来做到这一点。 如果我使用exec()并从命令行窗口运行脚本(它会在产生外部应用程序后立即返回到命令提示符),但如果使用相同命令创建Windows快捷方式,Perl脚本会挂起直到产生的外部应用程序退出或我手动关闭perl命令窗口。

有没有办法做到这一点? 我尝试过system , exec ,反引号,以及其他一些晦涩难懂的事情。 没有任何工作。

I am running ActiveState perl 5 on win7 x64. The solution does not have to be cross-platform.

I'm trying to use a Perl script to build a somewhat complex and variable command line argument string for another application. Then I want to execute that external application using the argument string while also immediately exiting the Perl script.

The idea is to create shortcut icons that run the Perl script with different arguments, which should generate the proper command line, spawn the external app (feeding it the proper arguments), and then go away immediately.

I can't seem to find any way to do this. It works if I use exec() and run the script from a command-line window (it returns to the command prompt right away after spawning the external app) but if I create a Windows shortcut using the same command, the Perl script just hangs around in the background forever until the spawned external app exits or I manually close the perl command window.

Is there any way to do this? I've tried system, exec, backticks, a couple of other obscure things. Nothing is working.

最满意答案

exec在Windows上不存在。 (Perl试图模拟它。)

如果您使用system或readpipe (又名反引号),Perl将继续运行,直到孩子完成(尽管它将空闲)。

您需要Win32 :: Process或system('start "" ...') 。

exec doesn't exist on Windows. (Perl tries to emulate it.)

If you use system or readpipe (aka backticks), Perl will continue to run until the child finishes (although it will be idle).

You need Win32::Process or system('start "" ...').

更多推荐

本文发布于:2023-08-05 19:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1439259.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   Execute   external   application   exit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!