1

I'm not being able to run my C program from the Git-bash terminal on my Windows machine. My code is compiling fine. The problem is just while running it. The command I'm using to compile my code is: gcc problem1.c

And the command that I'm giving for running the executable is ./a.exe

The error that I'm getting is this: bash: ./a.exe: Permission Denied

This problem has only recently cropped up. I've been compiling and running programs with git-bash for a long time and never faced this problem. A few days back, I enabled the Windows Subsystem for Linux on my Machine and installed the Ubuntu distribution. I don't know if that has something to do with this. I'm facing the same problem with CMD as well. CMD throws an access denied message when I try to run the code. Thanks in advance.

  • 1
    did you check the rigths of your binary? is it executable? (show use `ls -al a.exe`) – OznOg Feb 03 '19 at 14:24
  • since your working with a linux extension to windows, you need to use `chmod()` (read the MAN page) You might also need to use: `chown()` to take ownership of the executable. Remember that the directory also needs to have the appropriate permissions – user3629249 Feb 04 '19 at 00:52
  • I've figured out what was causing the problem. It was my bloody antivirus which was blocking the binary from executing. But after I added the file to the list of exceptions, it's executing again. – Tanuj Chakraborty Feb 06 '19 at 15:50

1 Answers1

0

Try setting first a simplified PATH to reference your Git bash:

set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%

Then try again executing your compiled exe.

With WSL activiated, some exe might require privilege elevation.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250