I am struggling to get the output for a Windows command that has a pipe in it. Here is the command:
systeminfo | findstr /B /C:"OS Name"
Here is the code:
c1 := exec.Command("systeminfo")
c2 := exec.Command("findstr", "/B", `/C:"OS Name"`)
r, w := io.Pipe()
c1.Stdout = w
c2.Stdin = r
var b2 bytes.Buffer
c2.Stdout = &b2
c1.Start()
c2.Start()
c1.Wait()
w.Close()
c2.Wait()
io.Copy(os.Stdout, &b2)
fmt.Println(b2)
Output: []
If I copy/paste the command in cmd, it will return results. Not sure why I can't get that reflected in my Go programme. I tried several variants, including the addition of "cmd", "/C" in the first command but no success either.