diff --git a/src/main/kotlin/kscript/app/AppHelpers.kt b/src/main/kotlin/kscript/app/AppHelpers.kt index 63c01290..1b4faa7c 100644 --- a/src/main/kotlin/kscript/app/AppHelpers.kt +++ b/src/main/kotlin/kscript/app/AppHelpers.kt @@ -23,8 +23,10 @@ data class ProcessResult(val command: String, val exitCode: Int, val stdout: Str fun evalBash(cmd: String, wd: File? = null, stdoutConsumer: Consumer = StringBuilderConsumer(), stderrConsumer: Consumer = StringBuilderConsumer()): ProcessResult { - return runProcess("bash", "-c", cmd, - wd = wd, stderrConsumer = stderrConsumer, stdoutConsumer = stdoutConsumer) + return runProcess( + *getBashCommandsForCurrentOS(), cmd, + wd = wd, stderrConsumer = stderrConsumer, stdoutConsumer = stdoutConsumer + ) } diff --git a/src/main/kotlin/kscript/app/OSHelpers.kt b/src/main/kotlin/kscript/app/OSHelpers.kt new file mode 100644 index 00000000..7858d542 --- /dev/null +++ b/src/main/kotlin/kscript/app/OSHelpers.kt @@ -0,0 +1,25 @@ +package kscript.app + +enum class OS { + WINDOWS, UNIX +} + +fun getOS(): OS { + val os = System.getProperty("os.name").toLowerCase() + return when { + os.contains("win") -> { + OS.WINDOWS + } + os.contains("nix") || os.contains("nux") || os.contains("aix") || os.contains("mac") -> { + OS.UNIX + } + else -> OS.UNIX + } +} + +val CURRENT_OS = getOS() + +fun getBashCommandsForCurrentOS() = when(CURRENT_OS){ + OS.WINDOWS -> arrayOf("sh", "-c") + OS.UNIX -> arrayOf("bash", "-c") +} \ No newline at end of file