简体   繁体   English

Java中的生成过程,类似于双击

[英]Spawn process in Java, similar as double-click

I have a Java application and i would like to spawn a new process(start a .bat file), that will essintially do the same thing as by double-clicking on it. 我有一个Java应用程序,我想产生一个新进程(启动.bat文件),该进程本质上会与双击它执行相同的操作。

I have tried both Runtime.getRuntime().exec() and ProcessBuilder in order to spawn that process. 我尝试了Runtime.getRuntime().exec()ProcessBuilder来生成该进程。 Both those approaches work (they can start the .bat file), but my problem is that they do not actually do the exact same thing as by double clicking on it. 这两种方法都可以工作(它们都可以启动.bat文件), 但是我的问题是,它们实际上并没有执行与双击它完全相同的操作。

More specifically, this .bat file starts up a JVM (java.exe MyMainClass) which is configured to run using Windows SxS (side by side). 更具体地说,此.bat文件将启动JVM(java.exe MyMainClass),该JVM配置为使用Windows SxS(并排)运行。 Thus, i have created appropriate java.exe.config and java.exe.manifest files. 因此,我创建了适当的java.exe.configjava.exe.manifest文件。 When i doulbe click on that, the java application starts and the appropriate .dlls are loaded succesfuly (reason i need SxS). 当我在doulbe上单击时,将启动Java应用程序,并成功加载相应的.dll(原因是我需要SxS)。

My problem is that when i start the exact same .bat file (with the exact same arguments and process environment), either by using ProcessBuilder or Runtime.getRuntime().exec() , it doesn't seem to take into consideration my SxS configuration, thus the .dlls that i need are not loaded at all, resulting in errors. 我的问题是,当我使用ProcessBuilderRuntime.getRuntime().exec()启动完全相同的.bat文件(具有完全相同的参数和进程环境)时,似乎没有考虑到我的SxS配置,因此我所需的.dll根本没有加载,从而导致错误。

Does anyone have any clue how to launch this .bat file the same way as windows laucnhes it when i am double clicking on it? 有没有人知道我双击该启动文件的方式,就像Windows启动该启动文件一样? Additionally, does anyone have any experience with Java SxS deployment? 此外,是否有人对Java SxS部署有任何经验? I cannot really understand why ProcessBuilder ignores my SxS configuration. 我真的不明白为什么ProcessBuilder会忽略我的SxS配置。

Thanks in advance. 提前致谢。

您可以尝试启动一个cmd窗口,该窗口会加载您的应用程序bat文件:

Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"C:\\path\\to\\the\\app.bat arg1 arg2\"");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM