()
| 146 | } |
| 147 | |
| 148 | func ExampleCommand_Feed() { |
| 149 | cmd := &com.Command{ |
| 150 | Binary: "bash", |
| 151 | Args: []string{ |
| 152 | "-c", "--", |
| 153 | "read line1; read line2; printf 'from stdin%s%s%s' \"$line1\" \"$line2\";", |
| 154 | }, |
| 155 | } |
| 156 | |
| 157 | // Use WithFeeder if you do want to perform additional tasks before feeding to stdin |
| 158 | cmd.WithFeeder(func() io.Reader { |
| 159 | time.Sleep(100 * time.Millisecond) |
| 160 | |
| 161 | return strings.NewReader("hello world\n") |
| 162 | }) |
| 163 | |
| 164 | // Or use the simpler Feed if you just want to pass along content to stdin |
| 165 | // Note that successive calls to WithFeeder / Feed will be written to stdin in order. |
| 166 | cmd.Feed(strings.NewReader("hello again\n")) |
| 167 | |
| 168 | err := cmd.Run(context.Background()) |
| 169 | if err != nil { |
| 170 | fmt.Println("Run err:", err) |
| 171 | |
| 172 | return |
| 173 | } |
| 174 | |
| 175 | exec, err := cmd.Wait() |
| 176 | if err != nil { |
| 177 | fmt.Println("Wait err:", err) |
| 178 | |
| 179 | return |
| 180 | } |
| 181 | |
| 182 | fmt.Println("Exit code:", exec.ExitCode) |
| 183 | fmt.Println("Stdout:") |
| 184 | fmt.Println(exec.Stdout) |
| 185 | fmt.Println("Stderr:") |
| 186 | fmt.Println(exec.Stderr) |
| 187 | |
| 188 | // Output: |
| 189 | // Exit code: 0 |
| 190 | // Stdout: |
| 191 | // from stdinhello worldhello again |
| 192 | // Stderr: |
| 193 | // |
| 194 | } |
| 195 | |
| 196 | func ExampleErrTimeout() { |
| 197 | cmd := &com.Command{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…