@@ -126,7 +126,7 @@ func (gc *GenericCommand) Run(expect *Expected) {
126
126
var env []string
127
127
output := & bytes.Buffer {}
128
128
stdout := ""
129
- errorGroup := & errgroup.Group {}
129
+ copyGroup := & errgroup.Group {}
130
130
var tty * os.File
131
131
var psty * os.File
132
132
if ! gc .async {
@@ -138,17 +138,37 @@ func (gc *GenericCommand) Run(expect *Expected) {
138
138
iCmdCmd .Stdin = tty
139
139
iCmdCmd .Stdout = tty
140
140
141
- gc .result = icmd .StartCmd (iCmdCmd )
142
-
143
- for _ , writer := range gc .ptyWriters {
144
- _ = writer (psty )
145
- }
146
-
147
141
// Copy from the master
148
- errorGroup .Go (func () error {
142
+ copyGroup .Go (func () error {
149
143
_ , _ = io .Copy (output , psty )
150
144
return nil
151
145
})
146
+
147
+ // Cautiously start the command
148
+ startGroup := & errgroup.Group {}
149
+ startGroup .Go (func () error {
150
+ gc .result = icmd .StartCmd (iCmdCmd )
151
+ if gc .result .Error != nil {
152
+ gc .t .Log ("start command failed" )
153
+ gc .t .Log (gc .result .ExitCode )
154
+ gc .t .Log (gc .result .Error )
155
+ return gc .result .Error
156
+ }
157
+
158
+ for _ , writer := range gc .ptyWriters {
159
+ err := writer (psty )
160
+ if err != nil {
161
+ gc .t .Log ("writing to the pty failed" )
162
+ gc .t .Log (err )
163
+ return err
164
+ }
165
+ }
166
+
167
+ return nil
168
+ })
169
+
170
+ // Let the error through for WaitOnCmd to handle
171
+ _ = startGroup .Wait ()
152
172
} else {
153
173
// Run it
154
174
gc .result = icmd .StartCmd (iCmdCmd )
@@ -161,7 +181,7 @@ func (gc *GenericCommand) Run(expect *Expected) {
161
181
if gc .pty {
162
182
_ = tty .Close ()
163
183
_ = psty .Close ()
164
- _ = errorGroup .Wait ()
184
+ _ = copyGroup .Wait ()
165
185
}
166
186
167
187
stdout = result .Stdout ()
0 commit comments