summaryrefslogtreecommitdiff
path: root/internal/io
diff options
context:
space:
mode:
authorPaul Bütow <pbuetow@mimecast.com>2020-02-16 13:10:02 +0000
committerPaul Bütow <pbuetow@mimecast.com>2020-02-16 13:10:02 +0000
commit1bdfd96a799726ff74b52955a25b216de62c14d2 (patch)
tree212a93dae1ec4818121e346e51ce35741e44e0c9 /internal/io
parent221010919b210034ba75d42951caf3965f66aa9d (diff)
drun can execute more complex commands, e.g. small shell scripts
Diffstat (limited to 'internal/io')
-rw-r--r--internal/io/run/run.go26
1 files changed, 14 insertions, 12 deletions
diff --git a/internal/io/run/run.go b/internal/io/run/run.go
index 3cf7935..5951cde 100644
--- a/internal/io/run/run.go
+++ b/internal/io/run/run.go
@@ -14,16 +14,16 @@ import (
// Run is for execute a command.
type Run struct {
- commandPath string
- args []string
- cmd *exec.Cmd
+ command string
+ args []string
+ cmd *exec.Cmd
}
// New returns a new command runner.
-func New(commandPath string, args []string) Run {
+func New(command string, args []string) Run {
return Run{
- commandPath: commandPath,
- args: args,
+ command: command,
+ args: args,
}
}
@@ -36,11 +36,11 @@ func (r Run) Start(ctx context.Context, lines chan<- line.Line) (pid int, ec int
pid = -1
if len(r.args) > 0 {
- logger.Debug(r.commandPath, r.args, " ")
- r.cmd = exec.CommandContext(ctx, r.commandPath, r.args...)
+ logger.Debug(r.command, r.args, " ")
+ r.cmd = exec.CommandContext(ctx, r.command, r.args...)
} else {
- logger.Debug(r.commandPath)
- r.cmd = exec.CommandContext(ctx, r.commandPath)
+ logger.Debug(r.command)
+ r.cmd = exec.CommandContext(ctx, r.command)
}
stdoutPipe, myErr := r.cmd.StdoutPipe()
@@ -60,8 +60,10 @@ func (r Run) Start(ctx context.Context, lines chan<- line.Line) (pid int, ec int
return
}
- pid = r.cmd.Process.Pid
- ec = 0
+ if r.cmd.Process != nil {
+ pid = r.cmd.Process.Pid
+ ec = 0
+ }
var wg sync.WaitGroup
wg.Add(2)