gpt4 book ai didi

java - 如何使用 apache commons-exec 启动程序并立即退出?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:53 31 4
gpt4 key购买 nike

通过使用 Apache Commons-Exec 我可以成功启动一个程序,但是启动程序在程序启动后挂起。

请问如何启动程序立即退出才不会阻塞后面的执行?

DefaultExecutor executor = new DefaultExecutor();
executor.execute( "cmd /c start C:\\Users\\xx\\program.exe");

我在 Win7 64 位上。

谢谢

最佳答案

根据 documentation , execute(CommandLine) 开始同步执行。也就是说,它会阻塞调用线程。您可能需要异步执行,因此请使用 execute(CommandLine command, ExecuteResultHandler handler)。例如,

DefaultExecutor executor = new DefaultExecutor();
executor.execute(new CommadLine("cmd /c start C:\\Users\\xx\\program.exe"),
new DefaultExecuteResultHandler());

关于java - 如何使用 apache commons-exec 启动程序并立即退出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13602635/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com