51

How can I execute a.exe using the Cygwin shell?

I created a C file in Eclipse on Windows and then used Cygwin to navigate to the directory. I called gcc on the C source file and a.exe was produced. I would like to run a.exe.

9 Answers 9

81

./a.exe at the prompt

1
  • 6
    ./a also works; Cygwin is smart enough to figure to treat a.exe as a (for compatibility with Unix, which doesn't use a default .exe suffix for executables). Commented Jun 1, 2015 at 21:18
11

you should just be able to call it by typing in the file name. You may have to call ./a.exe as the current directory is usually not on the path for security reasons.

6

just type ./a in the shell

2
  • 1
    Do you know why this works. ./a.exe makes sense but without extension this should not run. Any specific reason? Commented Oct 10, 2013 at 15:47
  • 1
    That would probably be cygwin figuring out things and being smart. UNIX-programs usually don't have a file extension, so if cygwin aims to give a UNIX-feeling on Windows it makes sense to give the option to let out the program file extension.
    – lindhe
    Commented Dec 18, 2014 at 22:23
3

gcc under cygwin does not generate a Linux executable output file of type " ELF 32-bit LSB executable," but it generates a windows executable of type "PE32 executable for MS Windows" which has a dependency on cygwin1.dll, so it needs to be run under cygwin shell. If u need to run it under dos prompt independently, they cygwin1.dll needs to be in your Windows PATH.

-AD.

2
  • How can i eliminate this dependancy if i want to run my program in another computer without cygwin Commented Feb 24, 2012 at 15:46
  • You can try to use -mno-cygwin to remove it, but then you are missing all the UNIX APIs it provides; -mno-cygwin is usually used with MinGW (www.mingw.org). Commented Mar 15, 2012 at 15:48
2

To execute a file in the current directory, the syntax to use is: ./foo

As mentioned by allain, ./a.exe is the correct way to execute a.exe in the working directory using Cygwin.

Note: You may wish to use the -o parameter to cc to specify your own output filename. An example of this would be: cc helloworld.c -o helloworld.exe.

2

Thomas wrote:

Apparently, gcc doesn't behave like the one described in The C Programming language

It does in general. For your program to run on Windows it needs to end in .exe, "the C Programming language" was not written with Windows programmers in mind. As you've seen, cygwin emulates many, but not all, features of a POSIX environment.

1

Apparently, gcc doesn't behave like the one described in The C Programming language, where it says that the command cc helloworld.c produces a file called a.out which can be run by typing a.out on the prompt.

A Unix hasn't behaved in that way by default (so you can just write the executable name without ./ at the front) in a long time. It's called a.exe, because else Windows won't execute it, as it gets file types from the extension.

-2

Just call it

> a

Make sure it will be found (path).

1
  • Putting the current directory . in your $PATH is a bad idea. If you want to execute a command in your current directory, type ./a. Commented Jun 1, 2015 at 21:18
-5

When you start in Cygwin you are in the "/home/Administrator" zone, so put your a.exe file there.

Then at the prompt run:

cd a.exe

It will be read in by Cygwin and you will be asked to install it.

1
  • cd changes to a specified directory. And if you've just created a .exe file by invoking the compiler you're not going to be asked to install anything. (And normally you won't be in /home/Administrator; you'll be in the home directory for your user name.) Commented Jun 1, 2015 at 21:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.