Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-application Java command line

I've been trying to figure out how to make a sort of command line within Java that acts similar to ComputerCraft's CraftOS interface using known libraries like jBASH and luaj, except it seems that anything I come across either isn't maintained anymore or doesn't function all too well. Unfortunately, dan200 keeps his source under lock and key, so I can't even see how he did it...

Does this mean I might end up having to create my own BASH-y shell and/or my own LUA-y scripting method, or is there something that's being maintained now that is at least somewhat usable?

like image 889
sctjkc01 Avatar asked May 19 '26 22:05

sctjkc01


2 Answers

Just to follow up my comment with some code;

Process p = Runtime.getRuntime().exec("/bin/bash");
InputStream stdout = p.getInputStream();
InputStream stderr = p.getErrorStream();
OutputStream stdin = p.getOutputStream();

And you would probably wrap those in BufferedReader and BufferedWriter respectively, so that you can use them as character streams, allowing you to do things like read and write lines of text. Eg;

BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout));
like image 58
lynks Avatar answered May 21 '26 14:05

lynks


BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell dynamically executes standard Java syntax and extends it with common scripting conveniences such as loose types, commands, and method closures like those in Perl and JavaScript.

like image 42
Ярослав Рахматуллин Avatar answered May 21 '26 12:05

Ярослав Рахматуллин



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!