From 3bc85a0d682a5157f9aaf7a4f9b424ffed47d2fd Mon Sep 17 00:00:00 2001 From: Dmitry Yunitsky Date: Thu, 17 May 2018 00:58:19 +0300 Subject: [PATCH] Redirect output on Windows. (#18) --- .../kotlin/com/gojuno/commander/android/Adb.kt | 2 +- .../android/{Emulator.kt => AdbDevice.kt} | 0 .../kotlin/com/gojuno/commander/os/Processes.kt | 14 ++++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) rename android/src/main/kotlin/com/gojuno/commander/android/{Emulator.kt => AdbDevice.kt} (100%) diff --git a/android/src/main/kotlin/com/gojuno/commander/android/Adb.kt b/android/src/main/kotlin/com/gojuno/commander/android/Adb.kt index 1bceb4f..0041bd4 100644 --- a/android/src/main/kotlin/com/gojuno/commander/android/Adb.kt +++ b/android/src/main/kotlin/com/gojuno/commander/android/Adb.kt @@ -42,7 +42,7 @@ fun connectedAdbDevices(): Observable> = process(listOf(adb, "dev .retry { retryCount, exception -> val shouldRetry = retryCount < 5 && exception is IllegalStateException if (shouldRetry) { - log("runningEmulators: retrying $exception.") + log("connectedAdbDevices: retrying $exception.") } shouldRetry diff --git a/android/src/main/kotlin/com/gojuno/commander/android/Emulator.kt b/android/src/main/kotlin/com/gojuno/commander/android/AdbDevice.kt similarity index 100% rename from android/src/main/kotlin/com/gojuno/commander/android/Emulator.kt rename to android/src/main/kotlin/com/gojuno/commander/android/AdbDevice.kt diff --git a/os/src/main/kotlin/com/gojuno/commander/os/Processes.kt b/os/src/main/kotlin/com/gojuno/commander/os/Processes.kt index 8c0b154..06ad2e7 100644 --- a/os/src/main/kotlin/com/gojuno/commander/os/Processes.kt +++ b/os/src/main/kotlin/com/gojuno/commander/os/Processes.kt @@ -63,8 +63,10 @@ fun process( val process: Process = ProcessBuilder(command) .redirectErrorStream(true) .let { - when (unbufferedOutput) { - true -> it.redirectOutput(os().nullDeviceFile()) + when { + unbufferedOutput && os() !== Windows -> { + it.redirectOutput(os().nullDeviceFile()) + } else -> it.redirectOutput(ProcessBuilder.Redirect.to(outputFile)) } } @@ -127,12 +129,12 @@ enum class Os { internal fun os(): Os { val os = System.getProperty("os.name", "unknown").toLowerCase(Locale.ENGLISH) - if (os.contains("mac") || os.contains("darwin")) { - return Mac + return if (os.contains("mac") || os.contains("darwin")) { + Mac } else if (os.contains("linux")) { - return Linux + Linux } else if (os.contains("windows")) { - return Windows + Windows } else { throw IllegalStateException("Unsupported os $os, only ${Os.values()} are supported.") }