0

In Java, how would I use a command line shell like cliche (can be found here) and launch it using an actual system command prompt shell? In my case "Terminal" for OSX.

I am trying to use it as the interface for my java application.

For example:

When the user types "hello" into the command prompt, the java application would print "Hello world".

Community
  • 1
  • 1
ThatGuy343
  • 2,354
  • 3
  • 30
  • 55
  • What exactly maps the input 'hello' back to 'Hello World'? Are you saying that you just want to have your program be runnable on the command line? Because if thats what your saying, you don't really have to do anything. – Amir Afghani Jul 09 '14 at 15:27
  • Depends on what you mean by runnable. I know you can launch Jar files using "java -jar EXAMPLE.jar". If you mean, do I want to have my java application run through command line and process/send input/output through it, then yes. – ThatGuy343 Jul 09 '14 at 15:28
  • send input and output to where? the shell? – Amir Afghani Jul 09 '14 at 15:30
  • thank you for your help :) i appreciate your time. And yes I want the user to be able to send commands through the shell, and the java application to print to the shell. – ThatGuy343 Jul 09 '14 at 15:30
  • then JSch is the answer - or you can use a ProcessBuilder and do Runtime.exec – Amir Afghani Jul 09 '14 at 15:32

2 Answers2

1

If I understood your question correctly, you can use JSch to connect to your local or remote sshd server and access the shell. There are many examples you can look at.

I am trying to use it as the interface for my java application.

That doesn't make sense - could you elaborate?

EDIT: Also, see this answer for an example of using Runtime.exec to possibly achieve what you want.

Community
  • 1
  • 1
Amir Afghani
  • 37,814
  • 16
  • 84
  • 124
0

For example, we have a Java file named Hello.java saved in document HelloWorld in Documents directory. Open terminal and type in $ cd Documents/HelloWorld Than type in command javac Hello.java. This command will compile Hello.java document and a file with a coffee sign next to it, named Hello should appear. After this, type to terminal command java Hello. This will launch the compiled file and down below should appear the text you wanted to be written

ddd
  • 1