19

I'm testing simple Go program on Windows 8 with SublimeText3 (GoSublime plugin)

go run -v example.go

and before run it's being compiled inside ..AppData\Local\Temp.. directory. My antivirus program thinks that it's a virus and blocks it:

fork/exec C:\Users\D24F7~1.KAP\AppData\Local\Temp\go-build333212398\command-line-arguments_obj\exe\example.exe: Access is denied.

I can't disable it and my solution is to change the folder where it's being compiled. How can I do that?

4 Answers 4

16

The GOTMPDIR environment var can be used to control the work directory. This is usually preferable to modifying the system-wide temporary directory. GOTMPDIR was introduced in go 1.10.

Before

> go run -work .\example.go
WORK=C:\Users\MyUserName\AppData\Local\Temp\go-build1002945170
...

Modify permanently in the System Properties > Environment Variables window or temporarily in the shell

# powershell
$env:GOTMPDIR = "C:\Users\MyUserName\MyGoBuilds"

After

> go run -work .\example.go
WORK=C:\Users\MyUserName\MyGoBuilds\go-build1381354702
...

Then you can make the needed antivirus or other security exceptions on the GOTMPDIR directory.

Sign up to request clarification or add additional context in comments.

Comments

3

The WORK directory (seen if building or running with the -x flag) is taken from the TMP environment variable. Updating that variable through the system properties will change the working directory.

Comments

0

I change ouput directory

go build -i -o D:\Users\MyProj\out\

-o flag

and put to antivirus ignoring D:\Users\MyProj\out\ directory

1 Comment

No, the OP asked about temporary build files, they have nothing to do with -o option.
-1

You can build a binary directly using go build (out binary is at current dir) or go build -o /your/custom/path. Then just run the output binary.

1 Comment

It's not a solution because in Windows Go compiles in temp folder - C:\Users\D24F7~1.KAP\AppData\Local\Temp_ - and only then copies it into _/your/custom/path. So it's sill Access denied error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.