19
src/jsMain/kotlin/com/infendro/shell/Shell.js.kt
Normal file
19
src/jsMain/kotlin/com/infendro/shell/Shell.js.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.infendro.shell
|
||||
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
import node.childProcess.ExecOptions
|
||||
import node.childProcess.exec
|
||||
|
||||
internal actual suspend fun execute(
|
||||
command: Array<String>,
|
||||
directory: String?,
|
||||
): Shell.Result = suspendCoroutine { continuation ->
|
||||
val command = command.joinToString(" ") { "\"$it\"" }
|
||||
val options = ExecOptions.invoke(cwd = directory)
|
||||
exec(command, options) { error, stdout, stderr ->
|
||||
val code = if (error == null) 0 else error.code!!.toInt()
|
||||
val value = if (error == null) stdout else stderr
|
||||
continuation.resume(Shell.Result(code, value))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user