aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/commands/Executor.kt
diff options
context:
space:
mode:
authorpacien2018-02-25 01:42:27 +0100
committerpacien2018-02-25 01:42:27 +0100
commitc6de35b7b283d1693c314559effd177cb912862b (patch)
tree03a8157dbb389222a45abaeabf85662ef99177ee /app/src/main/java/org/pacien/tincapp/commands/Executor.kt
parenteb31e3770f8c79ee0debb866e0fd56f9c37eb1be (diff)
downloadtincapp-c6de35b7b283d1693c314559effd177cb912862b.tar.gz
Add log viewer
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