The accepted answer doesn't read all lines, so I made a version that did:
def run_command(command):
p = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
line =return p.stdout.readlineiter()
while line:
yield line
line = p.stdout.readline(, b'')
Usage is the same as the accepted answer:
command = 'mysqladmin create test -uroot -pmysqladmin12'
for line in run_command(command):
print(line)
The accepted answer doesn't read all lines, so I made a version that did:
def run_command(command):
p = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
line = p.stdout.readline()
while line:
yield line
line = p.stdout.readline()
Usage is the same as the accepted answer:
command = 'mysqladmin create test -uroot -pmysqladmin12'
for line in run_command(command):
print(line)
The accepted answer doesn't read all lines, so I made a version that did:
def run_command(command):
p = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
return iter(p.stdout.readline, b'')
Usage is the same as the accepted answer:
command = 'mysqladmin create test -uroot -pmysqladmin12'
for line in run_command(command):
print(line)