sandeep gaur
sandeep gaur

Reputation: 85

Access denied executing compiled program

Using Windows, my Hello World code is in src\hello\hello.go.

When using the command "go run hello.go" Getting Error like this

# command-line-arguments


C:\go\pkg\tool\windows_amd64\link.exe: cannot create $WORK\b001\exe\a.out.exe: open $WORK\b001\exe\a.out.exe: Access is denied.

Upvotes: 2

Views: 3990

Answers (3)

mnhmilu
mnhmilu

Reputation: 2468

Adding code folder to the exception list solved the problem.

Windows Security-> Virus and Threat Protection Settings -> Exclutions->Add folder

Add your workplace folder here where your code exists. Adding temp folder didn't work for me.

go build gotest.go ; .\gotest.exe

Using the above command (regular command prompt.) can eliminate pop-up alerts but don't know the reason.

Upvotes: 0

Ferdy
Ferdy

Reputation: 1211

This can be caused by an anti-virus application like AVG or G-Data.

You can use the -o argument with go run to specify the output directory, and add that path to the exclude list of your anti-virus should this be the cause.

Upvotes: 4

Emily
Emily

Reputation: 1096

This usually happens when the executable is being edited in some way, or currently running. Check if you have any spare processes of this executable, or in the worst case, try restarting your computer.

Alternatively, it may also be that the linker genuinely does not have write access to the output directory. Make sure that the directory is writable to the user you are compiling your program as.

Upvotes: 1

Related Questions