2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-11-16 18:04:01 +00:00
|
|
|
//go:build windows
|
2017-08-02 15:01:21 +00:00
|
|
|
// +build windows
|
|
|
|
|
2017-10-25 09:18:07 +00:00
|
|
|
package exec
|
2017-08-02 15:01:21 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2017-10-25 09:18:07 +00:00
|
|
|
// Script returns a command to execute a script through a shell.
|
|
|
|
func Script(script string) (*exec.Cmd, error) {
|
2017-08-02 15:01:21 +00:00
|
|
|
shell := "cmd"
|
|
|
|
if other := os.Getenv("SHELL"); other != "" {
|
|
|
|
shell = other
|
|
|
|
}
|
2017-08-09 04:52:50 +00:00
|
|
|
script = "\"" + script + "\""
|
2017-08-02 15:01:21 +00:00
|
|
|
cmd := exec.Command(shell, "/C", script)
|
|
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
|
|
CmdLine: strings.Join(cmd.Args, " "),
|
|
|
|
}
|
|
|
|
return cmd, nil
|
|
|
|
}
|
2017-10-11 18:57:39 +00:00
|
|
|
|
|
|
|
func SetSysProcAttr(cmd *exec.Cmd) {}
|
|
|
|
|
|
|
|
func KillCommandSubtree(cmd *exec.Cmd) error {
|
|
|
|
return cmd.Process.Kill()
|
|
|
|
}
|