Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/wuseal/kscript-tools
- Owner: wuseal
- Created: 2022-08-19T20:07:14.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-19T22:33:45.000Z (about 1 year ago)
- Last Synced: 2024-10-16T00:36:18.641Z (4 months ago)
- Topics: command, kotlin, kscript, shell
- Language: Kotlin
- Homepage:
- Size: 79.1 KB
- Stars: 23
- Watchers: 4
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
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 scriptsexecute 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 outputexecute 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
```