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?
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.
Your problem is that you are using --windowed. Use --console instead, and it should print like normal!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With