I can’t find documentation on;
platform.posix…execlp
I can get it to work, and apparently I’m something of a expert on it;
But I am literarily digging through the web to find little bits of info.
Where is the API for it, I searched for it and no dice;
I am really wondering if I can pipe the std out and err back into Kotlin Native (i.e. in a program like GitHub - msink/kotlin-libui: Kotlin/Native interop to libui: a portable GUI library ) like I can in regular Java with Process and Buffers. I am able to get the error or result code (i.e. -1) etc.
Eventually I would like to embed a JVM in .exe files build by Katlin Native, if any one else is interested in this route please contact me scott@adligo.com (or reply on this thread :).
This C code seems to be the way it would be done using the POSIX wrappers;
Do the wrappers for pipe and dup exist in Kotlin?
Ok it did start working (on windows at least ) yea;
import kotlin.native.OsFamily.*
import platform.posix.*
import kotlinx.cinterop.refTo
import kotlinx.cinterop.toKString
fun main(arguments: Array<String>) {
println("running")
if (arguments.size >= 1) {
arguments.forEach { a -> println(a) }
}
val platform = Platform
val os = platform.osFamily
println("os is " + os)
when (os) {
WINDOWS -> runWindows()
else -> runUnix()
}
}
fun runWindows() {
val result = execl("dir", "","")
//hmm emulate https://gist.github.com/a-cordier/33211eda92b8084a9e7e
//https://www.youtube.com/watch?v=6xbLgZpOBi8
val fp = _popen("dir", "r") ?: error("Failed to run command: dir")
val buffer = ByteArray(4096)
var counter = 0
println("hmm")
while (true) {
val input = fgets(buffer.refTo(0), buffer.size, fp) ?: break
print(input.toKString())
//println(counter++)
}
println("Ran on windows $result");
}
fun runUnix() {
execlp("date", "","")
println("Ran on UNIX")
}