Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
✨ Added system commands
Browse files Browse the repository at this point in the history
  • Loading branch information
aquaslvt authored Jun 26, 2023
1 parent 29d07f5 commit 4f7eea8
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import api.printConsoleError
import commands.about
import commands.help
import java.net.InetAddress
import java.io.BufferedReader
import java.io.InputStreamReader

var version = "v3.0.0.1.od"
var username = System.getProperty("user.name")
Expand All @@ -16,10 +18,24 @@ fun main() {
var input = readln()

when (input) {
"help" -> help(version)
"exit" -> break
"fs help" -> help(version)
"fs exit" -> break
"fs about" -> about(version)
else -> printConsoleError("FS01", input)
else -> executeCommand(input)
}
}
}

private fun executeCommand(command: String) {
val process = Runtime.getRuntime().exec(command)
val reader = BufferedReader(InputStreamReader(process.inputStream))
var line: String?

while (reader.readLine().also { line = it } != null) {
println(line)
}

if (process.waitFor() != 0) {
api.printConsoleError("FS01", command)
}
}

0 comments on commit 4f7eea8

Please sign in to comment.