I am running command-line Python scripts from the Windows taskbar by having a shortcut pointing to the Python interpreter with the actual script as a parameter.
Afte
There's no need to wait for input before closing, just change your command like so:
cmd /K python <script>
The /K
switch will execute the command that follows, but leave the command interpreter window open, in contrast to /C
, which executes and then closes.
On windows 10 insert at beggining this:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Strange, but it work for me!(Together with input() at the end, of course)
import pdb
pdb.debug()
This is used to debug the script. Should be useful to break also.
The best option: os.system('pause')
<-- this will actually display a message saying 'press any key to continue' whereas adding just raw_input('')
will print no message, just the cursor will be available.
not related to answer:
os.system("some cmd command")
is a really great command as the command can execute any batch file/cmd commands.
In Windows, you can use the msvcrt module.
msvcrt.kbhit() Return true if a keypress is waiting to be read.
msvcrt.getch() Read a keypress and return the resulting character. Nothing is echoed to the console. This call will block if a keypress is not already available, but will not wait for Enter to be pressed.
If you want it to also work on Unix-like systems you can try this solution using the termios and fcntl modules.
One way is to leave a raw_input() at the end so the script waits for you to press enter before it terminates.
The advantage of using raw_input() instead of msvcrt.* stuff is that the former is a part of standard Python (i.e. absolutely cross-platform). This also means that the script window will be alive after double-clicking on the script file icon, without the need to do
cmd /K python <script>