6

I have written a script in python 3.5. I have made an .exe file of it using pyinstaller. The script has some print statements which are displayed in the console during execution. When i ran my script from command prompt i can see all the messages in my cmd but when i run .exe file from cmd than i do not see any msgs in command prompt. Is there any way to see msgs in command prompt from .exe file.

For example lets suppose below is my script named abc.py:

def sum():
   first = 5
   print('First number is {}'.format(first))
   second = 10
   result = first + second
   print('second number is {}'.format(second))
   print('Sum is = {}'.format(result))
 sum()

Now when i run this file from cmd like: python \pathto\abc.py, i can see all the messages in cmd. Now when i make .exe of this and now do something like \pathto\abc.exe from cmd then i do not see anything. Is there anyway to see ,msgs in a cmd from .exe file?

8
  • 1
    Basically, i do not see any message in the cmd. I have designed a gui as well, so i do see gui windows but nothing in cmd for messages. Commented Jan 22, 2018 at 17:50
  • 2
    Show the command you used to make the exe Commented Jan 22, 2018 at 18:32
  • 1
    @simon yes it works fine. No errors. Commented Jan 22, 2018 at 20:09
  • 1
    @qwerty this is my command: pyinstaller.exe --onefile --windowed abc.py I read documentation of pzinstaller from here: mborgerson.com/creating-an-executable-from-a-python-script Then, I tried to create exe by removing --windowed attribute as well but it did not work for me. Commented Jan 22, 2018 at 20:10
  • 2
    @umair butt On which OS? Have you tried with --console instead of --windowed? Commented Jan 22, 2018 at 20:34

2 Answers 2

9

First of all thanks for your support. I have found the solution.I was using: pyinstaller.exe --onefile --windowed myapp.py to generate my .exe file. From documentation i found out that --windowed prevents a console window from being displayed when the application is run. If you're releasing a non-graphical application (i.e. a console application), you do not need to use this option. So if you generate your exe with:

  pyinstaller.exe --onefile myapp.py 

and then run it via cmd, all the msgs will display in your cmd. Note: In this way you can also run your exe from cmd with command line arguments as well. For example suppose if in the above code variable:

first = sys.argv[1]

then running exe file from cmd like:

/exe/path 20

will also work. just keep in mind that sys.argv generates a string so in this case you need to convert 20 into integer.

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

Comments

5

Your problem is that you are using --windowed. Use --console instead, and it should print like normal!

3 Comments

yes this also works. If i dont use --console or --windowed then it works fine as well.
@umairbutt if this is the correct answer, it should be accepted.
i have already accepted but because of my reputation it is not showing here. Sorry.

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.