File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -180,6 +180,16 @@ func (c *Cmd) stdin() (f *os.File, err error) {
180
180
c .closeAfterWait = append (c .closeAfterWait , pw )
181
181
c .goroutine = append (c .goroutine , func () error {
182
182
_ , err := io .Copy (pw , c .Stdin )
183
+
184
+ // Ignore EPIPE errors copying to stdin if the program
185
+ // completed successfully otherwise.
186
+ // See Issue 9173.
187
+ if pe , ok := err .(* os.PathError ); ok &&
188
+ pe .Op == "write" && pe .Path == "|1" &&
189
+ pe .Err == syscall .EPIPE {
190
+ err = nil
191
+ }
192
+
183
193
if err1 := pw .Close (); err == nil {
184
194
err = err1
185
195
}
Original file line number Diff line number Diff line change @@ -765,3 +765,24 @@ func TestHelperProcess(*testing.T) {
765
765
os .Exit (2 )
766
766
}
767
767
}
768
+
769
+ // Issue 9173: ignore stdin pipe writes if the program completes successfully.
770
+ func TestIgnorePipeErrorOnSuccess (t * testing.T ) {
771
+ testenv .MustHaveExec (t )
772
+
773
+ // We really only care about testing this on Unixy things.
774
+ if runtime .GOOS == "windows" || runtime .GOOS == "plan9" {
775
+ t .Skipf ("skipping test on %q" , runtime .GOOS )
776
+ }
777
+
778
+ cmd := helperCommand (t , "echo" , "foo" )
779
+ var out bytes.Buffer
780
+ cmd .Stdin = strings .NewReader (strings .Repeat ("x" , 10 << 20 ))
781
+ cmd .Stdout = & out
782
+ if err := cmd .Run (); err != nil {
783
+ t .Fatal (err )
784
+ }
785
+ if got , want := out .String (), "foo\n " ; got != want {
786
+ t .Errorf ("output = %q; want %q" , got , want )
787
+ }
788
+ }
You can’t perform that action at this time.
0 commit comments