开发者

Is it possible to make command prompt in Java?

开发者 https://www.devze.com 2023-02-28 21:06 出处:网络
I would j开发者_如何学运维ust like to know whether it is possible to make a command prompt in Java.

I would j开发者_如何学运维ust like to know whether it is possible to make a command prompt in Java. My friend asked to make it, I wanted to know if it was possible or not. If it is possible, can someone suggest me some api or something? Thank you.

EDIT: I want to make it similar to windows command prompt

EDIT 2: I would like to make a SWING GUI application and put a command prompt inside of it.


Yes. Use the Process API.


You can run commands in Java using the Process API. You can also get the output and write input to the runned process. For more info, see this tutorial.

But if you want to make a terminal emulator (such as those in Linux) in Java,
I recommend having a look at JCTerm or JTA.


You must be careful how you start it.

If you start your program with java.exe then the console (input/output) is shown. With System.out.println("mymessage"); you can print (output) text to the console. With System.in you can read from the console. This delegates to the java.io.Console class (available throug System.console()).

If you start your program with javaw.exe, then you don't see the console. You must then create your own screen to allow input/output. This is the default on Windows.


Java can do console I/O and it can launch processes, so yes, it's possible. You'd use methods of System.in and System.out to display a prompt and read commands, and a ProcessBuilder to execute programs.


yes it's possible in java

your have to do some research on Java.lang & IO


Check the class java.lang.Runtime. It provides a couple of exec() methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消