In Go compiler, when I do "go run", executable file is stored to a temporary location. How to change this path to store the file in current working directory? I am using windows 7 64bit machine.
4 Answers
The folder used by Go to store the temporary executable can be changed by setting the GOTMPDIR environment variable.
More info here: https://stackoverflow.com/a/71197493/1057961
Comments
I agree with @Adrian and @Saleem, however, for interest sake, you can override the location (somewhat) by changing the location of your environment variable TEMP (or TMPDIR on OSX or Linux). This will still create a temporary directory in whatever directory you specify, in which the working files will be placed. Keep in mind that as Adrian and Saleem say, go run is intended for temporary runs.
And of course @JimB beat me to it with his comment which is really the essence of what I'm saying here.
go runis to execute application without storing of final executable on disk. That's the reason, it generates executable in temporary location and once done, file is ready to be disposed off.go runjust executesgo build -owith a temp path, executes the binary, then deletes it. If you don't want to do that, then don't usego run.