Skip to content

Commit

Permalink
set errors=backslashreplace
Browse files Browse the repository at this point in the history
  • Loading branch information
lucylq committed Jul 15, 2024
1 parent 0d1423e commit 18e0498
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions .github/scripts/run_with_env_secrets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io

Check warning

Code scanning / lintrunner

UFMT/format Warning

Run lintrunner -a to apply this patch.
import json
import os
import re
Expand All @@ -13,23 +14,25 @@ def run_cmd_or_die(cmd):
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
bufsize=1,
universal_newlines=True,
bufsize=-1,
)
p.stdin.write("set -e\n")
p.stdin.write(cmd)
p.stdin.write("\nexit $?\n")
p.stdin.close()
wrapped_stdin = io.TextIOWrapper(p.stdin, encoding="utf-8", errors='backslashreplace')
wrapped_stdin.write("set -e\n")
wrapped_stdin.write(cmd)
wrapped_stdin.write("\nexit $?\n")
wrapped_stdin.flush()
wrapped_stdin.close()

wrapped_stdout = io.TextIOWrapper(p.stdout, encoding='utf-8', errors='backslashreplace')
result = ""
while p.poll() is None:
line = p.stdout.readline()
line = wrapped_stdout.readline()
if line:
print(line, end="")
result += line

# Read any remaining output
for line in p.stdout:
for line in wrapped_stdout:
print(line, end="")
result += line

Expand Down

0 comments on commit 18e0498

Please sign in to comment.