@@ -142,11 +142,14 @@ func Serial(port, commandline string, extra Extra, l Logger) error {
142142 return program (z [0 ], z [1 :], l )
143143}
144144
145+ var cmds = map [* exec.Cmd ]bool {}
146+
145147// Kill stops any upload process as soon as possible
146148func 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+ }
150153 }
151154}
152155
@@ -257,14 +260,9 @@ func waitReset(beforeReset []string, l Logger, originalPort string) string {
257260 return port
258261}
259262
260- // cmd is the upload command
261- var cmd * exec.Cmd
262-
263263// program spawns the given binary with the given args, logging the sdtout and stderr
264264// through the Logger
265265func program (binary string , args []string , l Logger ) error {
266- defer func () { cmd = nil }()
267-
268266 // remove quotes form binary command and args
269267 binary = strings .Replace (binary , "\" " , "" , - 1 )
270268
@@ -278,7 +276,13 @@ func program(binary string, args []string, l Logger) error {
278276 extension = ".exe"
279277 }
280278
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+ }()
282286
283287 utilities .TellCommandNotToSpawnShell (cmd )
284288
0 commit comments