Fix native implementation
This commit is contained in:
20
src/macosMain/kotlin/com/infendro/shell/Shell.macos.kt
Normal file
20
src/macosMain/kotlin/com/infendro/shell/Shell.macos.kt
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.infendro.shell
|
||||
|
||||
import platform.posix.chdir
|
||||
import platform.posix.pclose
|
||||
import platform.posix.popen
|
||||
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"""" }
|
||||
if (directory != null) {
|
||||
chdir(directory)
|
||||
}
|
||||
val stream = popen(command, "r")!!
|
||||
val value = stream.readLines().joinToString("")
|
||||
val code = pclose(stream)
|
||||
|
||||
val result = Result.from(code, value)
|
||||
continuation.resume(result)
|
||||
}
|
||||
Reference in New Issue
Block a user