Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/kotlin/kscript/app/AppHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = StringBuilderConsumer(),
stderrConsumer: Consumer<String> = StringBuilderConsumer()): ProcessResult {
return runProcess("bash", "-c", cmd,
wd = wd, stderrConsumer = stderrConsumer, stdoutConsumer = stdoutConsumer)
return runProcess(
*getBashCommandsForCurrentOS(), cmd,
wd = wd, stderrConsumer = stderrConsumer, stdoutConsumer = stdoutConsumer
)
}


Expand Down
25 changes: 25 additions & 0 deletions src/main/kotlin/kscript/app/OSHelpers.kt
Original file line number Diff line number Diff line change
@@ -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")
}