Home Ask Login Register

Developers Planet

Your answer is one click away!

halfg33k February 2016

Interact with terminal application Java or C++

I'm trying to make a GUI that will interact with a terminal-based program, in this case the geth console for Ethereum. I'm able to start it up, but I have no idea how to send commands or retrieve output once it's running.

I've tried other programs, like Vim, but everything is totally separate from my program after it's started and I'm unable to give it any further commands.

After searching StackOverflow and matching solutions together, this is what I've come up with, and it's the closest I've come to success.

public static void main(String[] args) throws IOException{
        String[] command = {"gnome-terminal", "-e", "vim temp.txt"};

        Process proc = Runtime.getRuntime().exec(command);

        BufferedReader reader =  new BufferedReader(new InputStreamReader(proc.getInputStream()));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));


This will start Vim, creating temp.txt, but then Vim just sits open and the writer does nothing.

Is what I'm trying to do even possible?

P.S. I'm okay with C++, but I'd prefer Java for this as I'm more familiar with it.


Kenney February 2016

On the GO-Ethereum Wiki it says that it supports:

  • a JavaScript Console. You'd have to write the app in JavaScript itself - probably not an option here;
  • a JSON RPC server, in which case you'd communicate over a socket, not STDIN/OUT;
  • Commandline Options, in which case you would

    String[] command = {"geth", "help" };

Post Status

Asked in February 2016
Viewed 3,196 times
Voted 4
Answered 1 times


Leave an answer

Quote of the day: live life