|
32 | 32 | STDERR_FILE = "stderr.txt" |
33 | 33 |
|
34 | 34 | # Command line that writes the exit code of the previous command line and the shell's cwd to the |
35 | | -# terminal, as lines such as '?=0' and 'PWD=/drive'. |
| 35 | +# terminal, as lines such as '?=0' and 'PWD=/drive'. Some versions of coreutils env quote the |
| 36 | +# '?' name as in "'?'=0", so allow an optional character either side of it. |
36 | 37 | # Quote the grep pattern as cockle treats an unquoted '?' as a glob wildcard. |
37 | | -EXIT_CODE_AND_PWD_LINE = "env | grep -E '^(\\?|PWD)='" |
| 38 | +EXIT_CODE_AND_PWD_LINE = "env | grep -E '^(.?\\?.?|PWD)='" |
38 | 39 |
|
39 | 40 | # Collect the output of the open terminal so that we can tell when a command line has finished. |
40 | 41 | COLLECT_OUTPUT_JS = """ |
@@ -230,7 +231,8 @@ def read_exit_code_and_pwd(page: Page) -> tuple[int | None, str]: |
230 | 231 | output = run_line(page, EXIT_CODE_AND_PWD_LINE) |
231 | 232 | # Remove ANSI escape sequences such as colours, as grep is aliased to 'grep --color=auto'. |
232 | 233 | output = re.sub(r"\x1b\[[0-9;]*[A-Za-z]", "", output) |
233 | | - returncode = re.search(r"^\?=(-?\d+)\s*$", output, re.MULTILINE) |
| 234 | + # The '?' name may or may not be quoted, depending on the version of coreutils env. |
| 235 | + returncode = re.search(r"^'?\?'?=(-?\d+)\s*$", output, re.MULTILINE) |
234 | 236 | pwd = re.search(r"^PWD=(.*?)\s*$", output, re.MULTILINE) |
235 | 237 | if pwd is None: |
236 | 238 | raise RuntimeError(f"Unable to read PWD from terminal output: {output!r}") |
|
0 commit comments