Hide the command console window while running a GUI/Command line program on Windows
While running a command line program or some GUI initiated from command line on Windows, there is always a black console window on the screen. This sometime becomes annoying. For example, when you start the Eric Python IDE on Windows, normally you start it by calling a batch file “eric4.bat” which calls the actual eric4.py script sequentially. Since Eric4 is designed to be a GUI program, the black console window has no use but it is there. To prevent that or hide it, there are several ways.
- The best way is to use Windows script host (WSH). It needs to prepare a VB script as input, which starts the actual program you want to run. The VBscript file e.g. run.vbs contains “CreateObject(“Wscript.Shell”).run “cmd /c full_path_to\start.bat”,vbhide”. In start.bat, you can put anything you like there. The VBscript file must have the *.vbs extension name. It can be run by double clicking the file in explorer or even further encapsulated in another batch file. E.g. another run.bat containing “start run.vbs \n exit” will call the vbs file without waiting for its termination, then the vbs file does the stealth. This way the run.bat can be called either by double clicking or from the ‘run’ menu of the system Start menu.
As an example, for Eric4, there is a eric4.bat created in the python folder after installation. If you simply run it, you will get a black console window besides the main GUI window. You could create a eric4.vbs in python folder with this content “CreateObject(“WScript.Shell”).Run “runeric4.bat”,vbhide”; then rename the original eric4.bat to runeric4.bat. Finally, create a new eric4.bat with “@echo off \n start eric4.vbs \n exit” inside. Now you can start Eric4 by just calling the new eric4.bat from anywhere you like. No black window any more! - Some guy suggested using “iexpress” to pack your batch file. iexpress is a windows program allowing you to create a self-installing package. It also allows hiding the program while running it. It should not be difficult because it is a GUI wizard, although I did try it.
- Some other guy even suggested more ways (10!). But I think most of the methods mentioned there are trivial, because they just run a program in unusual ways, such as running the program as a system service or using at service to run it at background.
Hen Bu Cuo,Yeah~
I’ve also struggled with the console window. Looking at IDLE start script i found the way to start Eric without an open console window:
@echo off
rem Start Eric5 with command line parameters
set CURRDIR=%~dp0
start “%CURRDIR%\pythonw.exe” “%CURRDIR%\Lib\site-packages\eric5\eric5.pyw” %1 %2 %3 %4 %5 %6 %7 %8 %9
Thank you for sharing, Victor!Your solution is indeed easier!
I think the “.pyw” file extension plays the magic. It is intentionally used by python for the console-less applications. For more discussion on this, please see here http://www.velocityreviews.com/forums/t344026-how-to-run-python-in-windows-w-o-popping-a-dos-box.html .