When you run exec.Command(...)
it immediately goes and checks for the file's existence, but has to defer the error until you call Run()
, because the Command()
call doesn't return an error.
See here for the definition of Command
: http://golang.org/src/pkg/os/exec/exec.go?s=3410:3455#L99
It calls LookPath(...)
defined here: http://golang.org/src/pkg/os/exec/lp_unix.go?s=902:944#L23
You need to initialize the Command
after you know the file is there--after calling Run()
on your copy command.