使用 Runtime.exec 从 Java 应用程序启动 JVM 进程? [英] Launch JVM process from a Java application use Runtime.exec?
问题描述
我希望能够从现有的 Java 应用程序启动 Java 服务器进程并监视 stdoutput 和 stderror 并将该输出重定向到文件.是使用Runtime.exec"并像对待任何其他操作系统进程一样对待应用程序的最佳方法,还是有更适合新 JVM 的方法.
I want to be able to launch a Java server process from an existing java application and monitor the stdoutput and stderror and redirect that output to a file. Is the best approach to use 'Runtime.exec' and treat the app like any other OS process or is there something more suited for new JVMs.
这是在 Java 1.5 上
This is on Java 1.5
推荐答案
你应该使用 ProcessBuilder
,虽然我不知道其他的东西是否更适合你的情况(运行特别是 Java 进程).
Instead of Runtime
, you should probably use ProcessBuilder
, though I don't know if something else is even more appropriate in your case (running a Java process in particular).
这篇关于使用 Runtime.exec 从 Java 应用程序启动 JVM 进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!