2021-08-24 04:37:44 +08:00
|
|
|
//go:build windows
|
2020-02-29 02:46:03 +08:00
|
|
|
|
|
|
|
|
package execd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
2020-05-05 22:14:57 +08:00
|
|
|
"os"
|
|
|
|
|
"time"
|
2020-02-29 02:46:03 +08:00
|
|
|
|
|
|
|
|
"github.com/influxdata/telegraf"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (e *Execd) Gather(acc telegraf.Accumulator) error {
|
2020-06-05 07:09:22 +08:00
|
|
|
if e.process == nil {
|
2020-02-29 02:46:03 +08:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch e.Signal {
|
|
|
|
|
case "STDIN":
|
2020-06-05 07:09:22 +08:00
|
|
|
if osStdin, ok := e.process.Stdin.(*os.File); ok {
|
2020-05-05 22:14:57 +08:00
|
|
|
osStdin.SetWriteDeadline(time.Now().Add(1 * time.Second))
|
|
|
|
|
}
|
2020-06-05 07:09:22 +08:00
|
|
|
if _, err := io.WriteString(e.process.Stdin, "\n"); err != nil {
|
2020-05-05 02:09:10 +08:00
|
|
|
return fmt.Errorf("Error writing to stdin: %s", err)
|
|
|
|
|
}
|
2020-02-29 02:46:03 +08:00
|
|
|
case "none":
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Errorf("invalid signal: %s", e.Signal)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|