简体   繁体   English

Java面板中的命令提示

[英]Incude command prompt in Java panel

I have a batch file that checks out code from SVN and calls few commands on it.This happens on the windows command prompt. 我有一个批处理文件,可以从SVN中检出代码并在其中调用一些命令,这在Windows命令提示符下发生。 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. 我想从我的Java程序中调用此批处理文件,并且命令提示符必须出现在我的应用程序窗口的控制台中,而不是作为一个单独的窗口,以便我可以从我的应用程序中看到该批处理的输出。

Can anyone tell me how to include the command prompt to my console? 谁能告诉我如何将命令提示符包括到我的控制台中? I am using Swing. 我正在使用Swing。

If all you want is to see the output, forget the command prompt. 如果只想查看输出,请忘记命令提示符。

  1. Create a ProcessBuilder . 创建一个ProcessBuilder
  2. Call for the Process . 要求Process
  3. Read the output and error streams, and send them to something like MessageConsole . 读取输出和错误流,然后将它们发送到MessageConsole

MessageConsole

BTW - When (not if) you run into problems using a Process , see When Runtime.exec() won't & implement all the suggestions. 顺便说一句-当(如果不是)您使用Process遇到问题时,请参阅Runtime.exec()不会实现所有建议。

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. Java无法在JFrame中显示本机程序的GUI,即使目标程序实际上是为了允许其GUI出现在另一个程序的框架中而设计的。 You might get succeed if you use JNI program. 如果使用JNI程序,则可能会成功。

我自己还没有尝试过,但是如果您从Java代码启动程序并将该进程的PrintStream结果打印到控制台(stdout),这还不够吗?

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

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