NO

Author Topic: Can't run .exe program in Windows  (Read 4895 times)

ghoxxaz

  • Guest
Can't run .exe program in Windows
« on: April 24, 2014, 10:41:28 PM »
Hi guys!

So I am new to programmering and i follow à pdf file i found on Google. My question is, when i have compiled the code and built it i can execute the code, and it is successfull.

But, when i try to double click the .exe file in Windows Explorer it opens but shuts down almost immediately. Why?

Appreciate some explonation :)




Skickas från min iPhone via Tapatalk

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: Can't run .exe program in Windows
« Reply #1 on: April 24, 2014, 10:58:27 PM »
Console applications close immediately unless you tell them to wait for a keypress...

...
#include <conio.h>   // for _getch()
...
int main(int argc, char* argv[]) {
...
  _getch();
}

ghoxxaz

  • Guest
Re: Can't run .exe program in Windows
« Reply #2 on: April 24, 2014, 11:26:29 PM »
Thanks for the reply, and i Will test it the first thing tomorrow :)


Skickas från min iPhone via Tapatalk

czerny

  • Guest
Re: Can't run .exe program in Windows
« Reply #3 on: April 25, 2014, 08:06:20 AM »
Console applications close immediately unless you tell them to wait for a keypress...
As an alternative: You can open a cmd shell and run it there.

czerny

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Can't run .exe program in Windows
« Reply #4 on: April 25, 2014, 09:48:46 AM »
With right mouse button
2ExpMenuCmd.reg
Code: [Select]
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\*]
[HKEY_CURRENT_USER\Software\Classes\*\shell]
[HKEY_CURRENT_USER\Software\Classes\*\shell\Open With cmd]
[HKEY_CURRENT_USER\Software\Classes\*\shell\Open With cmd\command]
@="\"cmd.exe\" \"/k %1\""
May the source be with you

ghoxxaz

  • Guest
Re: Can't run .exe program in Windows
« Reply #5 on: April 25, 2014, 02:14:07 PM »
Thanks for the reply everyone! Appreciate it! :)

Well, the cmd window doesn't close as soon I double click the .exe file to run it, but it is a black cmd windows, and doesn't show the text unitl I hit a key but when the text shows up the cmd window closes.

---

#include <conio.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
      _getch();
      
   printf("\"Text that shows up!\"");
   return 0;
}
---

So, what am I doing wrong? hehe ^^ Please have patient with me :)

czerny

  • Guest
Re: Can't run .exe program in Windows
« Reply #6 on: April 25, 2014, 02:32:14 PM »
You should get a keypress after you display your text, not the other way around! czerny

ghoxxaz

  • Guest
Re: Can't run .exe program in Windows
« Reply #7 on: April 25, 2014, 02:56:13 PM »

You should get a keypress after you display your text, not the other way around! czerny

Yes, I understand what you mean, but when I tried to write  _getch(); after the text I didn't get any changes.


Skickas från min iPhone via Tapatalk

czerny

  • Guest
Re: Can't run .exe program in Windows
« Reply #8 on: April 25, 2014, 03:08:51 PM »
Yes, I understand what you mean, but when I tried to write  _getch(); after the text I didn't get any changes.
Have you compiled it?
Code: [Select]
#include <conio.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
    printf("\"Text that shows up!\"");
_getch();

    return 0;
}
« Last Edit: April 25, 2014, 03:14:26 PM by czerny »

ghoxxaz

  • Guest
Re: Can't run .exe program in Windows
« Reply #9 on: April 25, 2014, 03:11:35 PM »
Not sure, will try when i got home. thanks for replying :)


Skickas från min iPhone via Tapatalk

ghoxxaz

  • Guest
Re: Can't run .exe program in Windows
« Reply #10 on: April 27, 2014, 12:38:57 AM »
Solved :D I noticed that you czerny, wrote _getch(); after the text and before return. I wrote it after return so that was the problem :)


Skickas från min iPhone via Tapatalk

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Can't run .exe program in Windows
« Reply #11 on: April 27, 2014, 08:51:51 AM »
You know that RETURN exits the function immediately without executing any code after it?
---
Stefan

Proud member of the UltraDefrag Development Team

ghoxxaz

  • Guest
Re: Can't run .exe program in Windows
« Reply #12 on: April 27, 2014, 11:14:45 AM »
Yeah, I looked it up in my pdf file yesterday


Skickas från min iPhone via Tapatalk