Script not getting STDOUT from subprocess

Asked

Viewed 16 times

0

Problem

Well, basically I have this Python script that calls the CMD through the subprocess and writes a command in the CMD, however, I cannot print the STDOUT of the command I tried to execute

Doubt

What I should change in my script so that the "echo ola" command is printed in "for line in"?

Script

import subprocess

proc = subprocess.Popen('cmd.exe', stdin=subprocess.PIPE, stdout=subprocess.PIPE)

command = b'echo ola\n'
proc.stdin.write(command)

for line in proc.stdout:
    print("LINHA", line)

Exit

LINE: b'Microsoft Windows [Version 10.0.19042.746] r n'

LINE: b'(c) 2020 Microsoft Corporation. All Rights reserved. r n'

LINE: b' r n'

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.