How to split stdout of subprocess.run in python()
Code:
def run(self):
command = ls
result = subprocess.run(
[command],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True
)
self.returncode = result.returncode
self.stderr = result.stderr
self.stdout = result.stdout
os.chdir(CDW)
print(self.stderr)
Result:
b'file1.txt\nfile2.txt\nfile3\n'
Expected Result
file1
file2
file3