aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/commands/Executor.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/commands/Executor.kt')
-rw-r--r--app/src/main/java/org/pacien/tincapp/commands/Executor.kt18
1 files changed, 9 insertions, 9 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Executor.kt b/app/src/main/java/org/pacien/tincapp/commands/Executor.kt
index 39c413e..96e48b9 100644
--- a/app/src/main/java/org/pacien/tincapp/commands/Executor.kt
+++ b/app/src/main/java/org/pacien/tincapp/commands/Executor.kt
@@ -47,16 +47,16 @@ internal object Executor {
47 } 47 }
48 } 48 }
49 49
50 fun call(cmd: Command): CompletableFuture<List<String>> { 50 fun run(cmd: Command): Process = try {
51 val proc = try { 51 ProcessBuilder(cmd.asList()).start()
52 ProcessBuilder(cmd.asList()).start() 52 } catch (e: IOException) {
53 } catch (e: IOException) { 53 throw CommandExecutionException(e.message ?: "Could not start process.")
54 throw CommandExecutionException(e.message ?: "Could not start process.") 54 }
55 }
56 55
57 return supplyAsyncTask<List<String>> { 56 fun call(cmd: Command): CompletableFuture<List<String>> = run(cmd).let { process ->
58 if (proc.waitFor() == 0) read(proc.inputStream) 57 supplyAsyncTask<List<String>> {
59 else throw CommandExecutionException(read(proc.errorStream).lastOrNull() ?: "Non-zero exit status.") 58 if (process.waitFor() == 0) read(process.inputStream)
59 else throw CommandExecutionException(read(process.errorStream).lastOrNull() ?: "Non-zero exit status.")
60 } 60 }
61 } 61 }
62 62