44
55# Kommand
66
7- Kotlin Native library for create subprocesses and handle their I/O.
7+ Kotlin Native library for create sub-process and redirect their I/O.
88
9- # Supported Platforms
10-
11- - macOS-X64
12- - macOS-Arm64
13- - linux-X64
14- - linux-Arm64
15- - mingw-X64
16- - JVM
9+ # v2.0.0
1710
18- # Architecture
11+ Rust is an excellent language that takes into account both performance and engineering.
1912
20- ![ architecture ] ( assets/architecture_3.0.png )
13+ In version 1.x, we use the following API to provide the function of creating child processes
2114
22- # Dependent
15+ - ` fork ` of [ POSIX api]
16+ - ` CreateChildProcess ` of [ win32 api]
17+ - ` java.lang.ProcessBuilder ` of JVM
2318
24- - Heavily inspired by the rust-std ` Command ` .
25- - Based on the ` ktor-io ` , Inter-Process Communication(IPC) can be handled using pipes
26- - Kotlin Multiplatform 1.7.20 with new memory manager
19+ In version 2.0, we use the Rust standard library to provide the function of creating child processes.
2720
28- - ### Native for macOS/Linux
21+ - ` std::process::Command ` of Rust
22+ - ` java.lang.ProcessBuilder ` of JVM
2923
30- System calls using POSIX api
24+ It will bring
3125
32- - ### Native for Mingw
26+ - More unified API
27+ - Easier to use API
28+ - Performance is still excellent
29+ - Easier to maintain
30+ - Code structure is clearer
3331
34- System calls using Win32 api
32+ # Supported Platforms
3533
36- - ### JVM
34+ - x86_64-apple-darwin
35+ - aarch64-apple-darwin
36+ - x86_64-unknown-linux-gnu
37+ - aarch64-unknown-linux-gnu
38+ - x86_64-pc-windows-gnu (mingw-w64)
39+ - jvm
3740
38- Based ` java.lang.ProcessBuilder `
41+ # Dependent
3942
43+ - Rust Standard Library 1.69.0
44+ - Kotlin Multiplatform 1.9.21
4045
4146# Usage
4247
@@ -54,7 +59,8 @@ repositories {
5459// ……
5560
5661dependencies {
57- implementation(" com.kgit2:kommand:$lastVersion " )
62+ // should replace with the latest version
63+ implementation(" com.kgit2:kommand:2.x" )
5864}
5965
6066```
@@ -63,37 +69,54 @@ dependencies {
6369
6470### Inherit Standard I/O
6571
72+ https://github.com/kgit2/kommand/kommand-examples/example1/src/commonMain/kotlin/com/kgit2/kommand/Main.kt#L1-L12
73+
6674``` kotlin
67- Command (" ping" )
68- .arg(" -c" )
69- .args(" 5" , " localhost" )
70- .spawn()
71- .wait()
75+ import com.kgit2.kommand.process.Command
76+ import com.kgit2.kommand.process.Stdio
77+
78+ fun main () {
79+ Command (" ping" )
80+ .args(listOf (" -c" , " 5" , " localhost" ))
81+ .stdout(Stdio .Inherit )
82+ .spawn()
83+ .wait()
84+ }
7285```
7386
7487### Piped I/O
7588
89+ https://github.com/kgit2/kommand/kommand-examples/example2/src/commonMain/kotlin/com/kgit2/kommand/Main.kt#L1-L15
90+
7691``` kotlin
77- val child = Command (" ping" )
78- .args(" -c" , " 5" , " localhost" )
79- .stdout(Stdio .Pipe )
80- .spawn()
81- val stdoutReader: com.kgit2.io.Reader ? = child.getChildStdout()
82- val lines: Sequence <String > = stdoutReader?.lines()
83- lines.forEach {
84- println (it)
92+ import com.kgit2.kommand.process.Command
93+ import com.kgit2.kommand.process.Stdio
94+
95+ fun main () {
96+ val child = Command (" ping" )
97+ .args(listOf (" -c" , " 5" , " localhost" ))
98+ .stdout(Stdio .Pipe )
99+ .spawn()
100+ child.bufferedStdout()?.lines()?.forEach { line ->
101+ println (line)
102+ }
103+ child.wait()
85104}
86- child.wait()
87105```
88106
89107### Null I/O
90108
91109``` kotlin
92- Command (" gradle" )
93- .arg(" build" )
94- .stdout(Stdio .Null )
95- .spawn()
96- .wait()
110+ import com.kgit2.kommand.process.Command
111+ import com.kgit2.kommand.process.Stdio
112+
113+ fun main () {
114+ Command (" echo" )
115+ .arg(" nothing" )
116+ .stdout(Stdio .Null )
117+ .spawn()
118+ .wait()
119+ }
97120```
98121
99122## Build
0 commit comments