18 lines
620 B
Kotlin
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)
|
|
}
|
|
}
|