Change location of tmp

Can anyone advise if it is possible to, when running go code with “go run hello-world.go” to tell Go where to place and run the compiled .exe from? I am being asked not to use the C:Win\tmp folder as it is to be scanned and .exe’s blocked from running there in the next version of our corporate a/v product.

I can run a go build and get the .exe then run it, but that’s a messy and slow workflow.

Would greatly appreciate any assistance. Thanks.

hmm, I would suggest to run something like this go build <file> -o c:\path\to\my\binary && c:\path\to\my\binary . Not sure if this is an option for you.



Many thanks. Will get it a try. I had considered writing a little app which would call go build on the current buffer, send the output to a discrete place then run it. Which more or less is, I think, what your suggestion would do?

Before going there I just wanted to be sure that there was no easy way to change the default output of go run


Yeah I think it does exactly the same. In general I would suggest to use build “way” since run approach can be complicated when your app will get bigger (more files, tests ect)

Set the TMP env var.

C:\Users\esmarques>set TMP=c:\users\esmarques
C:\Users\esmarques>go run main.go
c:\users\esmarques\go-build735217614\b001\exe\main.exe: hi

Sample code used:

package main
import (
func main() {
	fmt.Printf("%s: hi\n", os.Args[0])

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.