blob: c93de6498dba3ed75a36bad630a1f872e0da2850 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package org.pacien.tincapp.commands
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
/**
* @author pacien
*/
internal object Executor {
init {
System.loadLibrary("exec")
}
/**
* @return -1 on error, forked child PID otherwise
*/
private external fun forkExec(argcv: Array<String>): Int
@Throws(IOException::class)
fun forkExec(cmd: Command) {
if (forkExec(cmd.asArray()) == -1)
throw IOException()
}
@Throws(IOException::class)
fun call(cmd: Command): List<String> {
val proc = ProcessBuilder(cmd.asList()).start()
val outputReader = BufferedReader(InputStreamReader(proc.inputStream))
return outputReader.readLines()
}
}
|