从Java应用程序启动JVM进程使用Runtime.exec? [英] Launch JVM process from a Java application use Runtime.exec?

查看:422
本文介绍了从Java应用程序启动JVM进程使用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

推荐答案

您应该使用运行时 http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html\"rel =noreferrer> 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).

这篇关于从Java应用程序启动JVM进程使用Runtime.exec?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆