Escape a string for use in a Windows batch file ECHO command. Escapes special shell characters that would otherwise be interpreted as redirections or command separators.
(s: str)
| 415 | |
| 416 | |
| 417 | def bat_echo_esc(s: str) -> str: |
| 418 | """Escape a string for use in a Windows batch file ECHO command. |
| 419 | |
| 420 | Escapes special shell characters that would otherwise be interpreted |
| 421 | as redirections or command separators. |
| 422 | """ |
| 423 | # ^ must be escaped first since it's the escape character |
| 424 | s = s.replace("^", "^^") |
| 425 | for c in ("&", "<", ">", "|"): |
| 426 | s = s.replace(c, f"^{c}") |
| 427 | return s |
| 428 | |
| 429 | |
| 430 | def check_required_env_vars(env_vars): |
no outgoing calls