Skip to content

Commit

Permalink
Codespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkrzyskow committed Mar 5, 2024
1 parent f7e05ae commit 475fe9c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,25 @@ def communicate(self, *args, **kwargs):

def __getattribute__(self, name_):
att = super().__getattribute__(name_)
if name_ == "stdout" and self.poll() is None:
print("Subprocess output:")
for line_ in att:
print(os.fsdecode(line_).rstrip())
if name_ == "stdout" and att is not None:
att.read = self.wrapper_read(att.read)
return att

@staticmethod
def wrapper_read(func):

if func.__name__ == "wrapper":
return func

def wrapper(*args, **kwargs):
output = func(*args, **kwargs)
print("Subprocess output:")
for line_ in os.fsdecode(output).split("\n"):
print(line_)
return output

return wrapper


subprocess.Popen = CustomPopen

Expand Down

0 comments on commit 475fe9c

Please sign in to comment.