- 扩展
String
类
- 扩展
Process
类
- 测试
fun String.execute(): Process {
val runtime = Runtime.getRuntime()
return runtime.exec(this)
}
fun Process.text(): String {
val inputStream = this.inputStream
val insReader = InputStreamReader(inputStream)
val bufReader = BufferedReader(insReader)
var output = ""
var line: String? =""
while (null!=line) {
line = bufReader.readLine()
output += line +"\n"
}
return output
}
fun testShell(): Unit {
val process = "ls -al".execute()
val exitCode = process.waitFor()
val text = process.text()
println(exitCode)
println(text)
}