You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ctx.run inside ctx.cd fails when path contains spaces on Windows #1001
@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?
Activity
jamesmyatt commentedon Oct 25, 2024
The escaping of the spaces in
cdis 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 commentedon Oct 30, 2024
:/ I'm new to working on windows - is there a workaround for this?
jamesmyatt commentedon Nov 6, 2024
@coilysiren , I just did it directly `ctx.run(f'cd "{wd}" && {cmd}')
jamesmyatt commentedon Nov 6, 2024
@bitprophet , @jefftriplett , I think that using
mslex: https://mslex.readthedocs.io/en/latest/ andshlex: https://docs.python.org/3/library/shlex.html (possibly viaoslex: https://github.com/petamas/oslex) to do the quoting would be the most robust way to do this quoting correctly.