4
4
5
5
# Kommand
6
6
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.
8
8
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
17
10
18
- # Architecture
11
+ Rust is an excellent language that takes into account both performance and engineering.
19
12
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
21
14
22
- # Dependent
15
+ - ` fork ` of [ POSIX api]
16
+ - ` CreateChildProcess ` of [ win32 api]
17
+ - ` java.lang.ProcessBuilder ` of JVM
23
18
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.
27
20
28
- - ### Native for macOS/Linux
21
+ - ` std::process::Command ` of Rust
22
+ - ` java.lang.ProcessBuilder ` of JVM
29
23
30
- System calls using POSIX api
24
+ It will bring
31
25
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
33
31
34
- System calls using Win32 api
32
+ # Supported Platforms
35
33
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
37
40
38
- Based ` java.lang.ProcessBuilder `
41
+ # Dependent
39
42
43
+ - Rust Standard Library 1.69.0
44
+ - Kotlin Multiplatform 1.9.21
40
45
41
46
# Usage
42
47
@@ -54,7 +59,8 @@ repositories {
54
59
// ……
55
60
56
61
dependencies {
57
- implementation(" com.kgit2:kommand:$lastVersion " )
62
+ // should replace with the latest version
63
+ implementation(" com.kgit2:kommand:2.x" )
58
64
}
59
65
60
66
```
@@ -63,37 +69,54 @@ dependencies {
63
69
64
70
### Inherit Standard I/O
65
71
72
+ https://github.com/kgit2/kommand/kommand-examples/example1/src/commonMain/kotlin/com/kgit2/kommand/Main.kt#L1-L12
73
+
66
74
``` 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
+ }
72
85
```
73
86
74
87
### Piped I/O
75
88
89
+ https://github.com/kgit2/kommand/kommand-examples/example2/src/commonMain/kotlin/com/kgit2/kommand/Main.kt#L1-L15
90
+
76
91
``` 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()
85
104
}
86
- child.wait()
87
105
```
88
106
89
107
### Null I/O
90
108
91
109
``` 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
+ }
97
120
```
98
121
99
122
## Build
0 commit comments