[Python] Multiple commands separated by newline in subprocess.Popen() with shell=True not...

Discussão em 'Python' iniciado por Stack, Maio 14, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to execute commands on the shell via Python on Windows and Linux and noticed a significant difference:

    import subprocess

    r = subprocess.run("echo 1\r\necho 2", shell=True, capture_output=True, text=True)
    print(r.stdout)


    On Windows, it prints

    1


    while on Linux it prints

    1
    2


    as expected.

    Why is the second echo not executed on Windows? I thought shell=True would allow multiple command like in a Batch/Shell script.

    Continue reading...

Compartilhe esta Página