2

I have created a batch script in order to start a custom Python script that I am running on Windows. However, what I could like to do is not have the command line window appear.

I did some research and I found that if I used the prefix START /B, the command line window will now appear.

cd %~dp0
START /B .\Modules\monitor.pyw

However, this method does not appear to work when I explicitly specify the Python executable like so:

cd %~dp0
START /B .\Python27\python .\Modules\monitor.pyw

The question is, why does the line above not work in the same way as the line with the explicit executable path? Thanks!

user1927638
  • 1,133
  • 20
  • 42
  • `cmd.exe` does not open a new console window for the application started with `start /B`. But a console window is opened for the execution of the batch file containing those 2 lines. And if Python itself creates a console window, the usage of option `/B` does not prevent creation of a console window. Check the documentation for [command line options of Python](https://docs.python.org/2/using/cmdline.html) if there is an option to avoid opening a console window. BTW: Better use `cd /D "%~dp0"` as first line. – Mofi Sep 07 '14 at 15:29
  • Note that I have set the extension of my python script to .pyw in order to prevent the console window from opening. – user1927638 Sep 07 '14 at 19:17
  • 1
    Possible duplicate of [How to hide console window in python?](http://stackoverflow.com/questions/764631/how-to-hide-console-window-in-python) – Fabian Feb 01 '17 at 06:04

1 Answers1

0

I do not have Python installed. But I suppose that a switch is needed on starting python.exe in Windows GUI mode or a different application.

I suggest to look which command is configured in Windows registry for opening a *.pyw file.

According to reply by ghostdog74 on What is the difference between .py and .pyw? I'm right with my assumption.

*.pyw must be interpreted with pythonw.exe instead of python.exe to run the Python script in Windows GUI mode instead of console mode.

So you have to change the command line by inserting character w.

Mofi
  • 46,139
  • 17
  • 80
  • 143