Using subprocess.Popen messing Ubuntu terminal output
import subprocess
import time
subprocess.Popen("sudo ./agt_internal", shell=True, cwd="/home/boblittle/AGT/")
time.sleep(10)
for i in range(10):
print('Good Morning America')
The terminal output is messed up. Any suggestions?
def start_agt_pmlog():
command = 'sudo ./agt_internal -unilog=PM'
args = shlex.split(command)
print(f'Starts AGT PMLog')
subprocess.Popen(args, shell=False, cwd="/home/boblittle/AGT/", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
I chaged the code with a suggested solution by adding the function above. It didn’t help.
2
Answers
Found a simple solution. Adding subprocess.run("reset", shell=True). It clears the terminal but it's good enough for me.
You should use shlex.split(), you have a missing double quote and also you should pass the stdout and stderr parameters to subprocess.Pope to avoid your terminal messing up.