https://kotlinlang.org logo
d

Dragos Rachieru

03/07/2022, 2:01 PM
Hello, I created a
sourceSet
called
desktopMain
like in this example The problem I'm facing, is that
platform.posix.popen
and
platform.posix.pclose
are not available in the shared
sourceSet
. Any idea why it is not resolved?
The
build.gradle
part:
Copy code
val desktopMain by creating {
    dependsOn(commonMain)
}
val linuxX64Main by getting {
    dependsOn(desktopMain)
}
val mingwX64Main by getting {
    dependsOn(desktopMain)
}
val macosX64Main by getting {
    dependsOn(desktopMain)
}
code
Copy code
actual fun runCommand(command: String) {
    system(command)
}
actual fun awaitCommand(
    command: String
): String {
    val fp = popen(command, "r") ?: error("Failed to run command: $command")
    val buffer = ByteArray(4096)
    val returnString = StringBuilder()
    var scan = fgets(buffer.refTo(0), buffer.size, fp)
    if (scan != null) {
        while (scan != NULL) {
            returnString.append(scan!!.toKString())
            scan = fgets(buffer.refTo(0), buffer.size, fp)
        }
    }
    val status = pclose(fp)
    if (status != 0) {
        error("Command $command failed with status $status")
    }
    return returnString.toString()
}
system
call works
m

msink

03/07/2022, 3:56 PM
I'm not sure, but maybe
popen
and
pclose
are not supported in mingw. Does it work if comment out mingw support?
d

Dragos Rachieru

05/02/2022, 10:29 AM
@msink I tried again today, looks like
popen
and
pclose
work on
linux
and
macos
For mingw I have to use
_popen
and
_pclose
, don't know why.
16 Views