I ended up using a process handler (more precisely, com.intellij.execution.process.OSProcessHandler) from the Intellij IDEA + platform API, writing my own small command structure in which each command is known as executing itself (write) and analyze the response from the process (read )
source
share