Timeout for waiting of results of stty is set.
@@ -128,7 +128,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
public class OConsoleDatabaseApp extends OrientConsole implements OCommandOutputListener, OProgressListener {
@@ -167,8 +167,6 @@ public class OConsoleDatabaseApp extends OrientConsole implements OCommandOutput
new OSignalHandler().installDefaultSignals(signal -> restoreTerminal());
-
-
if (tty)
console.setReader(new TTYConsoleReader(console.historyEnabled()));
@@ -214,9 +212,12 @@ public class OConsoleDatabaseApp extends OrientConsole implements OCommandOutput
* Execute the specified command and return the output (both stdout and stderr).
*/
protected static int exec(final String[] cmd) throws IOException, InterruptedException {
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ final AtomicInteger exitValue = new AtomicInteger(-1);
+ Thread terminalThread = new Thread(() -> {
+ try {
+ final ByteArrayOutputStream bout = new ByteArrayOutputStream();
- Process p = Runtime.getRuntime().exec(cmd);
+ final Process p = Runtime.getRuntime().exec(cmd);
int c;
InputStream in = p.getInputStream();
@@ -230,9 +231,22 @@ public class OConsoleDatabaseApp extends OrientConsole implements OCommandOutput
bout.write(c);
}
- p.waitFor(10, TimeUnit.SECONDS);
+ p.waitFor();
+
+ exitValue.set(p.exitValue());
+ } catch (IOException | InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ });
+
+ terminalThread.start();
+ terminalThread.join(10 * 1_000);
+
+ if (terminalThread.isAlive()) {
+ terminalThread.interrupt();
+ }
- return p.exitValue();
+ return exitValue.get();
}
@ConsoleCommand(aliases = {
