Files
shell.kt/src/jsMain/kotlin/com/infendro/shell/Shell.js.kt
2026-02-15 14:06:35 +01:00

18 lines
620 B
Kotlin

package com.infendro.shell
import node.childProcess.ExecOptions
import node.childProcess.exec
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
actual suspend fun execute(vararg command: String, directory: String?): Result = suspendCoroutine { continuation ->
val command = command.joinToString(" ") { """"$it"""" }
val options = ExecOptions(cwd = directory)
exec(command, options) { error, stdout, stderr ->
val code = error?.code?.toInt() ?: 0
val result = Result.from(code, { stdout as String }, { stderr as String })
continuation.resume(result)
}
}