Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
clarkb7 opened this issue Jul 29, 2024 · 2 comments
Open

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

clarkb7 opened this issue Jul 29, 2024 · 2 comments

Comments

@clarkb7
Copy link

clarkb7 commented Jul 29, 2024

example

@task
def repro(ctx):
    import tempfile
    d = tempfile.mkdtemp(prefix="with space")
    with ctx.cd(d):
        ctx.run("whoami")

output

The system cannot find the path specified.

debug output

The system cannot find the path specified.
invoke.program.run: Received a possibly-skippable exception: <UnexpectedExit: cmd='cd C:\\Users\\BRANDE~1.CLA\\AppData\\Local\\Temp\\with\\ spacekk8c0niv && whoami' exited=1>

it looks like ctx.cwd improperly escapes the whitespace for Windows by adding a backslash. If using the cd command this way the path should be enclosed in double quotes. Why do you use the cd command instead of the cwd parameter to subprocess.Popen?

@jamesmyatt
Copy link

The escaping of the spaces in cd is definitely wrong for Windows. Needs to be enclosed in " or escaped with ^ or ``` depending on whether it's using CMD or Powershell. e.g. https://www.howtogeek.com/694949/how-to-escape-spaces-in-file-paths-on-the-windows-command-line/.

@coilysiren
Copy link

:/ I'm new to working on windows - is there a workaround for this?

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

No branches or pull requests

3 participants