Skip to content

Quote Windows paths with spaces in Context.cd() - #1088

Open
r3wretrhy wants to merge 1 commit into
pyinvoke:mainfrom
r3wretrhy:fix-windows-cd-spaces
Open

r3wretrhy wants to merge 1 commit into
pyinvoke:mainfrom
r3wretrhy:fix-windows-cd-spaces

Conversation

@r3wretrhy

Copy link
Copy Markdown

Context.cd prefixes run/sudo with cd <path> &&. Spaces in the path were always turned into POSIX foo\ bar. That is valid for bash, but cmd.exe treats the backslash as a path separator, so Windows fails with "The system cannot find the path specified."

On Windows, leave the space in cwd and quote the cd argument instead. POSIX still backslash-escapes. Paths without spaces are unchanged on both platforms.

Tests: pytest tests/context.py (new cases patch WINDOWS so they run on POSIX CI too).

Fixes #1001

POSIX still backslash-escapes spaces. cmd.exe does not treat a backslash-space as an escaped space, so quote the path instead.

Fixes pyinvoke#1001.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ctx.run inside ctx.cd fails when path contains spaces on Windows

1 participant