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".

5
  • 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. Commented Jul 9, 2014 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. Commented Jul 9, 2014 at 15:28
  • send input and output to where? the shell? Commented Jul 9, 2014 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. Commented Jul 9, 2014 at 15:30
  • then JSch is the answer - or you can use a ProcessBuilder and do Runtime.exec Commented Jul 9, 2014 at 15:32

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

mmm that's a bit overboard, why do I need an sshd server just to have a command prompt as menu for a local Java application.
I've added an example to the question
I didn't realize i could use the Runtime.exec for this. thanks
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.