From 1300d75c10c71640c62e454b9893f4373755a936 Mon Sep 17 00:00:00 2001 From: Terence Boldt Date: Sun, 28 Mar 2021 22:24:47 +0000 Subject: [PATCH] Updated driver to support working directory --- RaspberryPi/Driver.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/RaspberryPi/Driver.go b/RaspberryPi/Driver.go index 200b7d6..222660c 100644 --- a/RaspberryPi/Driver.go +++ b/RaspberryPi/Driver.go @@ -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")