1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] python - subprocess cannot use stdout with CREATE_NEW_CONSOLE

Discussão em 'Python' iniciado por Stack, Novembro 23, 2025.

  1. Stack

    Stack Membro Participativo

    test.bat

    @echo off
    for /L %%i in (40, -1, 10) do (
    echo working %%i test1
    ping localhost -n 2 > nul
    )
    echo Done!


    main.py

    import subprocess

    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    startupinfo.wShowWindow = 5
    process1 = subprocess.Popen('test.bat', stdout=subprocess.PIPE, text=True, creationflags=subprocess.CREATE_NEW_CONSOLE)

    while process1.poll() is None:
    test1 = process1.stdout.readline()
    print(test1.rstrip(), flush=True)


    What is the point of creationflags=subprocess.CREATE_NEW_CONSOLE ... if the console window has nothing inside it ... because the output is being redirected with stdout=subprocess.PIPE?

    Is there a way subprocess.popen opens the actual bat file (with output visible in the console window) ... and forks off the stdout=subprocess.PIPE into a variable ... at the same time? (without saving stdout=subprocess.PIPE into a text file)

    Continue reading...

Compartilhe esta Página