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) }