@@ -142,11 +142,14 @@ func Serial(port, commandline string, extra Extra, l Logger) error {
142
142
return program (z [0 ], z [1 :], l )
143
143
}
144
144
145
+ var cmds = map [* exec.Cmd ]bool {}
146
+
145
147
// Kill stops any upload process as soon as possible
146
148
func Kill () {
147
- log .Println (cmd )
148
- if cmd != nil && cmd .Process .Pid > 0 {
149
- cmd .Process .Kill ()
149
+ for cmd := range cmds {
150
+ if cmd .Process .Pid > 0 {
151
+ cmd .Process .Kill ()
152
+ }
150
153
}
151
154
}
152
155
@@ -257,14 +260,9 @@ func waitReset(beforeReset []string, l Logger, originalPort string) string {
257
260
return port
258
261
}
259
262
260
- // cmd is the upload command
261
- var cmd * exec.Cmd
262
-
263
263
// program spawns the given binary with the given args, logging the sdtout and stderr
264
264
// through the Logger
265
265
func program (binary string , args []string , l Logger ) error {
266
- defer func () { cmd = nil }()
267
-
268
266
// remove quotes form binary command and args
269
267
binary = strings .Replace (binary , "\" " , "" , - 1 )
270
268
@@ -278,7 +276,13 @@ func program(binary string, args []string, l Logger) error {
278
276
extension = ".exe"
279
277
}
280
278
281
- cmd = exec .Command (binary , args ... )
279
+ cmd := exec .Command (binary , args ... )
280
+
281
+ // Add the command to the map of running commands
282
+ cmds [cmd ] = true
283
+ defer func () {
284
+ delete (cmds , cmd )
285
+ }()
282
286
283
287
utilities .TellCommandNotToSpawnShell (cmd )
284
288
0 commit comments