Skip to content

Commit 8fa9559

Browse files
Improve output handling in subprocess call
Co-authored-by: user202729 <[email protected]>
1 parent 0b6ad58 commit 8fa9559

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/sage/env.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
we normalize it, but keep in mind that ``SAGE_ROOT`` may also be
99
``None``::
1010
11+
sage: # long time
1112
sage: env = {k:v for (k,v) in os.environ.items() if not k.startswith("SAGE_")}
12-
sage: from subprocess import check_output
13+
sage: from subprocess import run, PIPE
1314
sage: module_name = "sage.all" # hide .all import from the linter
1415
sage: cmd = f"from {module_name} import SAGE_ROOT, SAGE_LOCAL;"
1516
sage: cmd += "from os.path import samefile;"
@@ -19,9 +20,13 @@
1920
....: cmd += f"s1 = samefile(SAGE_ROOT, '{SAGE_ROOT}');"
2021
sage: cmd += f"s2 = samefile(SAGE_LOCAL, '{SAGE_LOCAL}');"
2122
sage: cmd += "print(s1 and s2);"
22-
sage: out = check_output([sys.executable, "-c", cmd], env=env).decode().strip() # long time
23-
sage: out == "True" # long time
24-
True
23+
sage: out = run([sys.executable, "-c", cmd], env=env, stdout=PIPE, stderr=PIPE, check=False, text=True, encoding='u8', errors='replace')
24+
sage: out.returncode
25+
0
26+
sage: out.stdout.strip()
27+
'True'
28+
sage: out.stderr.strip()
29+
''
2530
2631
AUTHORS:
2732

0 commit comments

Comments
 (0)