Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wuseal/kscript-tools

Tools for Kotlin/Kscript to easy run shell command in kotlin code
https://github.com/wuseal/kscript-tools

command kotlin kscript shell

Last synced: 4 months ago
JSON representation

Tools for Kotlin/Kscript to easy run shell command in kotlin code

Awesome Lists containing this project

README

        

# Kscript Tools

Easy way to run shell command line in kotlin and other tools

## Usage

### Used in [kscript](https://github.com/holgerbrandl/kscript):

```kotlin
@file:DependsOn("com.sealwu:kscript-tools:1.0.22")
```

### Used in normal kotlin gradle projects

add into gradle dependencies

```kotlin
dependencies {
implementation("com.sealwu:kscript-tools:1.0.22")
}
```

## APIs

### `runCommand`
Run a bash/shell command in kotlin code, also can run multi-lines bash/shell scripts

execute next kotlin code
```kotlin
"ls".runCommand()
```
output on console:
```shell
Applications Downloads MavenDep Pictures iOSProjects
Desktop IdeaProjects Movies Public scripts
Documents Library Music StudioProjects
```

### `evalBash`
Run a bash/shell command in kotlin code, also can run multi-lines bash/shell scripts,
The different with `runCommand` is that it can get the command run standard output and error output

execute next kotlin code
```kotlin
val date = evalBash("date").getOrThrow() //execute shell command `date` and get the command's output and set the content to date variable
println(date) //This will print Fri Aug 19 21:59:56 CEST 2022 on console
val year = date.substringAfterLast(" ") // will get 2022 and assign to `year`
println(year)
```

output on console:
```shell
Fri Aug 19 21:59:56 CEST 2022
2022
```