Fix ping2

This commit is contained in:
Super User
2024-05-08 15:42:47 +03:00
parent e03e5e7c47
commit deca713acc
3 changed files with 20 additions and 41 deletions

View File

@@ -78,31 +78,6 @@
}, nil
}
func (app *App) copyAndCapture(r io.Reader, strWin string) ([]byte, error) {
var out []byte
buf := make([]byte, 1024, 1024)
for {
n, err := r.Read(buf[:])
if n > 0 {
d := buf[:n]
out = append(out, d...)
str := strings.Trim(string(d), "\n\r")
app.Log("Std: %s", str)
app.Ping2SendStr(str)
}
if err != nil {
// Read returns io.EOF at the end of file, which is not an error for us
if err == io.EOF {
err = nil
}
return out, err
}
}
}
func (app *App) Ping2SendObj(obj map[string]interface{}) (error) {
if app.CliCur == nil {
app.Log("No cli")
@@ -113,14 +88,14 @@ func (app *App) copyAndCapture(r io.Reader, strWin string) ([]byte, error) {
return nil
}
/*
func (app *App) Ping2SendStr(str string) (error) {
return app.Ping2SendObj(map[string]interface{}{
"data" : "stdout",
"string": str,
})
}
*/
@@ -136,7 +111,11 @@ func (app *App) ping2Capture(r io.Reader, strWin string) ([]byte, error) {
app.Log("Std: %s", str)
app.Ping2SendStr(str)
app.Ping2SendObj(map[string]interface{}{
"data" : "stdout",
"win" : strWin,
"string": str,
})
}
if err != nil {
// Read returns io.EOF at the end of file, which is not an error for us