ProcessBuilder显示启动java应用程序的控制台

ProcessBuilder显示启动java应用程序的控制台

本文介绍了Java ProcessBuilder显示启动java应用程序的控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JAVA应用程序启动(使用ProcessBuilder)另一个JAVA应用程序,如下所示:

  String val =something ; 
ProcessBuilder processBuilder = new ProcessBuilder(java, - classpath,dir,appName,val);
流程p = processBuilder.start();

现在,这工作正常,appName使用参数val启动,它运行并运行...很好...问题是没有控制台窗口出现... appName做了很多输出到控制台,我们需要看到它......我怎么能用控制台启动这个过程?



我正在尝试的东西(CMD.exe,java, - classpath,dir,appName,val)等...但我无法正确...



另外,我无法重定向流,我的程序实际上可以启动这些appName的5-10个,每个应该都有自己的控制台窗口显示自己的信息。 / p>

我们非常感谢任何帮助。
谢谢,

解决方案

只有从控制台执行java ....时才存在Console对象否则,获取一个的调用返回null。



如果要查看控制台,则需要打开命令shell控制台(例如windows cmd .exe或Unix bash shell窗口)并输入:

  java -classpath =...com.example.appName arg1 

如果你想以不同的方式运行,不好意思,登录到控制台不适合你。相反,使用下列之一记录:




  • log4j

  • slf4j

  • logback


I have a JAVA application that launches (using ProcessBuilder) another JAVA application like this:

String val = "something";
ProcessBuilder processBuilder = new ProcessBuilder("java", "-classpath", dir, appName, val);
Process p = processBuilder.start();

Now, this works fine, appName is launched with the parameter val and it runs and works ... great ... the problem is no Console Window appears ... appName does a LOT of outputting to the console and we need to see it ... how can I start the process with a console?

I am trying stuff like ("CMD.exe", "java", "-classpath", dir, appName, val), etc... but I can't get it right ...

Also, I can't redirect the streams, my program can actually start 5-10 of these appName's, each should have their own console window showing their own information.

Any help would be much appreciated.Thanks,

解决方案

A Console object only exists when you execute java.... from a console. Otherwise, the call to obtain one returns null.

If you want to see a console, you need to open a command shell console (e.g. windows cmd.exe or Unix bash shell window) and type:

java -classpath="..." com.example.appName arg1

If you want to run in a different manner, sorry to say, logging to Console is not for you. Instead, log using one of:

  • log4j
  • slf4j
  • logback

这篇关于Java ProcessBuilder显示启动java应用程序的控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 03:59