Skip to content

Commit

Permalink
Temp
Browse files Browse the repository at this point in the history
  • Loading branch information
BppleMan committed Dec 25, 2023
1 parent 15f7e01 commit af7c721
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name: Kommand Test

on:
push:
branches: [ "main", "dev", "v2.0" ]
branches: [ "main", "dev" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
Expand Down
105 changes: 64 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,44 @@

# Kommand

Kotlin Native library for create subprocesses and handle their I/O.
Kotlin Native library for create sub-process and redirect their I/O.

# Supported Platforms

- macOS-X64
- macOS-Arm64
- linux-X64
- linux-Arm64
- mingw-X64
- JVM
# v2.0.0

# Architecture
Rust is an excellent language that takes into account both performance and engineering.

![architecture](assets/architecture_3.0.png)
In version 1.x, we use the following API to provide the function of creating child processes

# Dependent
- `fork` of [POSIX api]
- `CreateChildProcess` of [win32 api]
- `java.lang.ProcessBuilder` of JVM

- Heavily inspired by the rust-std `Command`.
- Based on the `ktor-io`, Inter-Process Communication(IPC) can be handled using pipes
- Kotlin Multiplatform 1.7.20 with new memory manager
In version 2.0, we use the Rust standard library to provide the function of creating child processes.

- ### Native for macOS/Linux
- `std::process::Command` of Rust
- `java.lang.ProcessBuilder` of JVM

System calls using POSIX api
It will bring

- ### Native for Mingw
- More unified API
- Easier to use API
- Performance is still excellent
- Easier to maintain
- Code structure is clearer

System calls using Win32 api
# Supported Platforms

- ### JVM
- x86_64-apple-darwin
- aarch64-apple-darwin
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- x86_64-pc-windows-gnu (mingw-w64)
- jvm

Based `java.lang.ProcessBuilder`
# Dependent

- Rust Standard Library 1.69.0
- Kotlin Multiplatform 1.9.21

# Usage

Expand All @@ -54,7 +59,8 @@ repositories {
// ……

dependencies {
implementation("com.kgit2:kommand:$lastVersion")
// should replace with the latest version
implementation("com.kgit2:kommand:2.x")
}

```
Expand All @@ -63,37 +69,54 @@ dependencies {

### Inherit Standard I/O

https://github.com/kgit2/kommand/kommand-examples/example1/src/commonMain/kotlin/com/kgit2/kommand/Main.kt#L1-L12

```kotlin
Command("ping")
.arg("-c")
.args("5", "localhost")
.spawn()
.wait()
import com.kgit2.kommand.process.Command
import com.kgit2.kommand.process.Stdio

fun main() {
Command("ping")
.args(listOf("-c", "5", "localhost"))
.stdout(Stdio.Inherit)
.spawn()
.wait()
}
```

### Piped I/O

https://github.com/kgit2/kommand/kommand-examples/example2/src/commonMain/kotlin/com/kgit2/kommand/Main.kt#L1-L15

```kotlin
val child = Command("ping")
.args("-c", "5", "localhost")
.stdout(Stdio.Pipe)
.spawn()
val stdoutReader: com.kgit2.io.Reader? = child.getChildStdout()
val lines: Sequence<String> = stdoutReader?.lines()
lines.forEach {
println(it)
import com.kgit2.kommand.process.Command
import com.kgit2.kommand.process.Stdio

fun main() {
val child = Command("ping")
.args(listOf("-c", "5", "localhost"))
.stdout(Stdio.Pipe)
.spawn()
child.bufferedStdout()?.lines()?.forEach { line ->
println(line)
}
child.wait()
}
child.wait()
```

### Null I/O

```kotlin
Command("gradle")
.arg("build")
.stdout(Stdio.Null)
.spawn()
.wait()
import com.kgit2.kommand.process.Command
import com.kgit2.kommand.process.Stdio

fun main() {
Command("echo")
.arg("nothing")
.stdout(Stdio.Null)
.spawn()
.wait()
}
```

## Build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import com.kgit2.kommand.process.Command
import com.kgit2.kommand.process.Stdio

fun main() {
Command("ping")
.args(listOf("-c", "5", "localhost"))
.stdout(Stdio.Inherit)
Command("echo")
.arg("nothing")
.stdout(Stdio.Null)
.spawn()
.wait()
TODO("Need other more representative examples")
}

0 comments on commit af7c721

Please sign in to comment.