ProcessKt is a versatile open-source project designed to simplify and enhance the execution of shell commands, providing a seamless experience for developers working with Kotlin. This project empowers users to effortlessly integrate and manage shell commands within their Kotlin applications, fostering efficiency and flexibility in command-line operations.
<dependency>
<groupId>dev.junsung</groupId>
<artifactId>process-kt</artifactId>
<version>1.0.0</version>
</dependency>
implementation("dev.junsung:process-kt:1.0.0")
Process.run("ls", "-la")
Process.run()
returns BufferedReader
.
// read all output into single String
val text: String = Process.run("ls", "-la").readText()
// read all output but split into lines
val lines: List<String> = Process.run("ls", "-la").readLines()
// read the first line of output
val firstLine: String = Process.run("ls", "-la").readLine()
The default directory is current directory (File(".")
).
Process.run("ls", "-la", directory = File("/"))
Set timeout using kotlin.time.Duration
.
Process.run("ls", "-la", timeout = 1.minutes)