I'm trying to figure out if it's possible to start...
# kotlin-native
k
I'm trying to figure out if it's possible to start an executeable and wait for it to close. I have found https://stackoverflow.com/questions/51460921/kotlin-native-execute-an-executable, but that uses the "exec" family which won't return after the process is finished it seems?
Looking a it furter, It seems I could fork and then exec, but that leaves the issue of waiting for the exit of the child process
k
Thank you so much
a
If your application run on
posix
you can run and read program output by
popen("your program", "r")
something like
Copy code
return sequence {
            val fp: CPointer<FILE>? = requireNotNull(popen(command, "r"))
            try {
                val buffer = ByteArray(4096)
                while (true) {
                    val scan = fgets(buffer.refTo(0), buffer.size, fp)
                    if (scan != null && scan != NULL) {
                        yield(scan.toKString())
                    } else {
                        break
                    }
                }
            } finally {
                pclose(fp)
            }
        }
k
that piece of code is to read files no?
anyway, was still helpful, cause I just realised i forgot to call fclose
a
It reads output of posix program. Try it gor “ls” 😉
k
huh
In my case I just need to wait for it to end so system will probably work fine 😃