-1

I've converted a python script to an exe file using pyinstaller, whenever I open the exe the program, it flashes for a second and automatically shuts down itself.

The program is a simple one. Here's the code snippet:

print("Hello World")
Kapil
  • 817
  • 2
  • 13
  • 25
  • 3
    The window closes when the program execution finishes. If you add a `input()` call at the end it will wait for you to press enter to close. – CMMCD Aug 01 '19 at 13:14
  • 2
    Perhaps add something like `input("Press Enter to exit")` at the end. – jasonharper Aug 01 '19 at 13:14
  • That's the same like in your IDE: if you run your python program it will be finished within fractions of a second. Any further waiting duration to see the output _while the program is still running_, needs you to program this behaviour. – SpghttCd Aug 01 '19 at 13:14

2 Answers2

1

Add something like input("Press something to exit") or time.sleep(10) function at the end of your programm to have a standby at the end of the main function

cocool97
  • 1,201
  • 1
  • 10
  • 22
0

If for whatever reason you can't or don't want to edit the code, you may be able to see the output of the compiled version by opening the file from the command prompt.

cd /D C:\location\of\the\file
myFile.exe
deeBo
  • 836
  • 11
  • 24
  • 1
    `cd` **`/D`** `...`! – aschipfl Aug 01 '19 at 13:32
  • Wow, I've somehow never heard of that flag for cd! I always end up doing something like E: then cd etc. – deeBo Aug 01 '19 at 14:09
  • Yes, I think `/D` didn't exist in DOS times, I remember to have done these two steps also... – aschipfl Aug 01 '19 at 14:17
  • It would also be better to use doublequotes, i.e. `CD /D "C:\location\of\the\file"` and `"myFile.exe"` or `Start "" /Wait "myFile.exe"`. It would also be prudent to include a `Pause`/`Timeout` to allow for time to read any output from the command(s). – Compo Aug 02 '19 at 08:08