17

I'm a complete newbie to coding, so I don't understand most of the similar posts on this forum.

I'm doing a simple C programming course, and I need to run a notepad++ file from the Powershell. The file only contains this:

#include <stdio.h> 

 int main()
  {
    int num = 931;

    printf("The number 'num' is %d\n", num);
    return 0; 
}   

I called the file: Variables.c then I put this into the Powershell:

PS C:\Users\Raven\Desktop\C Programming> gcc Variables.c -o Variables.exe 

Followed by:

PS C:\Users\Raven\Desktop\C Programming> Variables.exe

I then get the following error:

Variables.exe : The term 'Variables.exe' is not recognized as the name of a cmdlet, funct ion, script file, or operable program. Check the spelling of the name, or if a path was i ncluded, verify that the path is correct and try again. At line:1 char:1
+ Variables.exe
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Variables.exe:String) [], CommandNotFound     Exception
    + FullyQualifiedErrorId : CommandNotFoundException

What is going on here??

Many thanks in advance!

3
  • Did you check the output of gcc to be sure that it actually compiled the code? Does executing dir in the powershell prompt to list the contents of the directory include a file called Variables.exe? Commented Sep 7, 2017 at 11:16
  • Hey Tom, not sure how to check the output of gcc..? But yes the dir command lists the Variables.exe file Commented Sep 7, 2017 at 11:21
  • By 'output' I mean the diagnostic information printed to the console. I don't recall exactly what the default is, but it should print something to tell you whether it succeeded or failed. If you see nothing at all, that's a problem. Commented Sep 7, 2017 at 11:33

2 Answers 2

26

To run an exe in PowerShell you need to either provide the full path to the exe or the relative path by preceding the filename with .\ Ensure you are in the correct directory and try:

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

2 Comments

D'oh! Yes, of course. This is one of Powershell's most common and irritating quirks.
Woww thanks a lot, it worked!! You've made my day :)
1

The case is you are using windows powershell. You can execute that fileName.exe command in windows cmd (in the exe file stored path).

Comments

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.