Updated driver to support working directory

This commit is contained in:
Terence Boldt 2021-03-28 22:24:47 +00:00
parent a16de00a13
commit 1300d75c10

View File

@ -50,6 +50,8 @@ const SaveFileCommand = 7
var debug bool = false
var workingDirectory string = "/home"
func main() {
host.Init()
@ -132,7 +134,18 @@ func handleExecCommand() {
fmt.Printf("Reading command to execute...\n")
linuxCommand, err := readString()
fmt.Printf("Command to run: %s\n", linuxCommand)
if strings.HasPrefix(linuxCommand, "cd /") {
workingDirectory = strings.Replace(linuxCommand, "cd ", "", 1)
writeString("Working directory set")
return
}
if strings.HasPrefix(linuxCommand, "cd ") {
workingDirectory = workingDirectory + "/" + strings.Replace(linuxCommand, "cd ", "", 1)
writeString("Working directory set")
return
}
cmd := exec.Command("bash", "-c", linuxCommand)
cmd.Dir = workingDirectory
cmdOut, err := cmd.Output()
if err != nil {
fmt.Printf("Failed to execute command\n")