How do I pipe data between processes in Go?

Piping data between processes in Go can be achieved using the `os/exec` package, which allows you to execute commands and handle their output and input streams easily.

By using the `Cmd` struct, you can set up a command pipeline that connects the output of one command directly to the input of another.

Keywords: Go, process, piping, os/exec, command, output, input, streams.
Description: This example demonstrates how to pipe data between processes in Go using the os/exec package.

package main

import (
    "fmt"
    "os/exec"
    "strings"
)

func main() {
    // Create the first command
    cmd1 := exec.Command("echo", "Hello, World!")
    
    // Create the second command
    cmd2 := exec.Command("wc", "-c")
    
    // Get the output pipe from the first command
    stdout, _ := cmd1.StdoutPipe()
    
    // Assign the output pipe to the second command
    cmd2.Stdin = stdout
    
    // Start the first command
    cmd1.Start()
    
    // Start the second command
    cmd2.Start()
    
    // Wait for the first command to finish
    cmd1.Wait()
    
    // Get the output from the second command
    output, _ := cmd2.Output()
    
    // Print the output
    fmt.Printf("Number of bytes: %s", output)
}
    

Keywords: Go process piping os/exec command output input streams.