Calling String followed by Exec returns a string ending with a new line (i.e. \n).
Example:
out, err := script.Exec("echo hello").String()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%q\n", out)
It prints: "hello\n"
Is this intended or the \n shouldn't be there?
If I'm not mistaken the issue is that os/exec.Command returns it. Execute this example
package main
import (
"bytes"
"fmt"
"log"
"os/exec"
)
func main() {
out := &bytes.Buffer{}
cmd := exec.Command("echo", "hello")
cmd.Stdout = out
err := cmd.Start()
if err != nil {
log.Fatal(err)
}
cmd.Wait()
fmt.Printf("%q\n", out.String())
}
And you see that it prints: "hello\n"
Calling
Stringfollowed byExecreturns a string ending with a new line (i.e.\n).Example:
It prints:
"hello\n"Is this intended or the
\nshouldn't be there?If I'm not mistaken the issue is that
os/exec.Commandreturns it. Execute this exampleAnd you see that it prints:
"hello\n"