I'm working on a proof of concept for a command line tool written in Kotlin/Native, as it seems to be an ideal language and runtime for cross-platform binaries.
This command line tool needs to regularly interact with operating system executables, commands and/or shell functions in the os user $PATH or shell environment. However, I don't see any examples in kotlin-native samples or documentation anywhere that might indicate how to:
- execute an operating system executable or $PATH command
- obtain the execution's return code (integer)
- ensure the executed process's stdin, stdout and stderr file descriptor streams can be represented as OutputStream and InputStreams respectively
In JVM-land, we'd use java.lang.ProcessBuilder for all of this, but that's apparently not available in Kotlin/Native.
I found the cinterop/posix platform.posix.system function, but that doesn't give you access to the process's streams.
In my web research, I found a really nice C tutorial that indicates the only clean way to do this is with fork and dup2 and such, but it's not clear to me if or how that would translate to Kotlin/Native code.
fork()anddup2got to be in theplatform.posix.*, distributed with the compiler. Are you sure, that this is not enough?