From 68c25fa13937ed65df65991c5af78fd5f5418a4f Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 25 Mar 2017 15:58:55 +1300 Subject: [PATCH] webcmd: allow setting custom WorkingDir for process --- Task.go | 4 +++- config.go | 5 +++-- twa_NewTask.go | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Task.go b/Task.go index 4adddab..5195182 100644 --- a/Task.go +++ b/Task.go @@ -41,7 +41,7 @@ func uuid() string { } // LaunchTask creates a new task from the given command parameters. -func (this *App) LaunchTask(params []string) (taskRef string, err error) { +func (this *App) LaunchTask(workDir string, params []string) (taskRef string, err error) { if len(params) == 0 { return "", errors.New("No parameters for task") } @@ -60,6 +60,8 @@ func (this *App) LaunchTask(params []string) (taskRef string, err error) { return "", err } + cmd.Dir = workDir + err = cmd.Start() if err != nil { return "", err diff --git a/config.go b/config.go index 14fd4a2..a634109 100644 --- a/config.go +++ b/config.go @@ -22,8 +22,9 @@ type InputParam struct { } type CommandConfig struct { - Title string - Execution []InputParam // TODO allow plain strings as a shorthand for PARAMTYPE_CONST + Title string + WorkingDir string // default empty-string: getcwd() + Execution []InputParam // TODO allow plain strings as a shorthand for PARAMTYPE_CONST } type AppConfig struct { diff --git a/twa_NewTask.go b/twa_NewTask.go index 9ba24ee..2f9d54f 100644 --- a/twa_NewTask.go +++ b/twa_NewTask.go @@ -58,7 +58,7 @@ func (this *App) Action_NewTask(w http.ResponseWriter, r *http.Request) { } // Create new command from supplied values - taskRef, err := this.LaunchTask(params) + taskRef, err := this.LaunchTask(taskInfo.WorkingDir, params) if err != nil { fail(w, r, err.Error()) return