MCPcopy Create free account
hub / github.com/containerd/nerdctl / ExampleCommand_Feed

Function ExampleCommand_Feed

mod/tigron/internal/com/package_example_test.go:148–194  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

146}
147
148func 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
196func ExampleErrTimeout() {
197 cmd := &com.Command{

Callers

nothing calls this directly

Calls 5

WithFeederMethod · 0.95
FeedMethod · 0.95
RunMethod · 0.95
WaitMethod · 0.95
BackgroundMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…