0

I'm making a little tool that handles a sort of exotic device, with lots of options to manage it etc. One of them would be to scan for tty ports, find the right one then throw the user to "minicom" with some parameters for example.

How can I make java completely exit while running a specific command, under certain condition, after such exit ?

Initial thoughts would be to use a bash script, scan the return value, communicate via files etc.A fully functional interactive serial console in Java would be the dream, but the ones I try right now can't seem to even find tty ports now.

2
  • If I understand you correctly, you want do in Java what would be a fork+exec in C, right? Here is a somewhat bizarre solution which might work, but maybe it would be better to reconsider the architecture of your application instead. Commented Apr 30, 2020 at 6:30
  • Wow, that's exactly the kind of stunt I was looking for. It's so "cool" I should indeed definitely stay away ahah but nice to know it's possible. I'm doing what you suggest, and realized I don't really want to dump minicom to my users anyway, and I'll focus on making more tailored serial port features (like downloading a file, for which Java is surprisingly vastly better than minicom) with a md doc for those who'd like to raw-browse the device. Commented Apr 30, 2020 at 10:32

1 Answer 1

1

Most processes on linux follow a call stack where process A calls process B which calls process C. Wen process C terminates, the control goes back to process B, and so on.

It sounds like in this case you want java to call minimum, but when java is finished, return to the parent shell.

I am not aware of any way you can terminate a JVM upon a call to another process (returning to the JVM's parent when it terminates). Perhaps with some clever C calls using JNI, but that isn't really java anymore and could create new problems.

You could have the JVM wrap the target process and pass through the user inputs and outputs. Alternatively, use file communication, e.g. the java program writes the command-line to a file, that the parent bash script executes after the JVM terminates, but that is a bit of a kludge.

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

1 Comment

Yeah I don't like very much the idea of redoing the input/output capture myself because then I lose a lot of linux own very well done terminal emulation ( | less, etc) and minicom is pretty cool for serial console communication. I suppose writing the command somewhere and making the calling script detect such commands is the way to go. I'll leave this open for a bit and accept your answer if no one else has better ideas :)

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.