Incude command prompt in Java panel

≡放荡痞女 提交于 2021-02-16 05:31:45

问题


I have a batch file that checks out code from SVN and calls few commands on it.This happens on the windows command prompt. I want to call this batch file from my java program and the command prompt must be present in the console of my application window and not as a separate window so I can see the output of the batch from my application.

Can anyone tell me how to include the command prompt to my console? I am using Swing.


回答1:


If all you want is to see the output, forget the command prompt.

  1. Create a ProcessBuilder.
  2. Call for the Process.
  3. Read the output and error streams, and send them to something like MessageConsole.

MessageConsole

BTW - When (not if) you run into problems using a Process, see When Runtime.exec() won't & implement all the suggestions.




回答2:


Answer is "no, you can't do that".

Java cannot display a native program's GUI within a JFrame, even if the target program was actually architected to allow it's GUI to be presented within another program's frame. You might get succeed if you use JNI program.




回答3:


I haven't tried it myself, but wouldn't it be enough if you start the Program from your java code and print the results of the PrintStream of that Process to your console (stdout)?



来源:https://stackoverflow.com/questions/10135844/incude-command-prompt-in-java-panel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!