Python – subprocess. Popen creates flags

subprocess. Popen creates flags… here is a solution to the problem.

subprocess. Popen creates flags

I want to generate a child process, it would be nice if everything happened in the background without opening a new Windows console.

First I think there is a problem with my code because it causes an error when sending input to a child process.
A command like String, for example, produces an error

Unknown Action: tring

Meaning, sometimes the first character of input sent to the child process via stdin.write is lost.

Here is the code:

    self.sp = subprocess. Popen(
        stdin=subprocess. PIPE,
        stdout=subprocess. PIPE,
        stderr=subprocess. PIPE

Now I have tried the following method and everything works fine. The problem is the newly opened consoled.

    self.sp = subprocess. Popen(
        stdin=subprocess. PIPE,
        stdout=subprocess. PIPE,
        stderr=subprocess. PIPE,
        creationflags = subprocess. CREATE_NEW_CONSOLE

Is there another way to achieve this without opening a new Windows console?

Your link leads me to the description of the CREATE_NEW_WINDOW logo

A process can also create a console by specifying the
CREATE_NEW_CONSOLE flag in a call to CreateProcess. This method
creates a new console that is accessible to the child process but not
to the parent process. Separate consoles enable both parent and child
processes to interact with the user without conflict. If this flag is
not specified when a console process is created, both processes are
attached to the same console, and there is no guarantee that the
correct process will receive the input intended for it.
can prevent confusion by creating child processes that do not inherit
handles of the input buffer, or by enabling only one child process at
a time to inherit an input buffer handle while preventing the parent
process from reading console input until the child has finished.

It would be nice if it was possible to create a new console without opening the window.

This seems to solve the problem


Thank you.


“Is there another way to do this without opening a new Windows console?”
Right here !
You can create flags using the CREATE_NO_WINDOW as follows:

creationflags=subprocess. CREATE_NO_WINDOW

Look at! No window!

Related Problems and Solutions