Space in the user path will cause several of the SFDX commands to fail on Windows

Issue #1935 resolved
Matthew Gladman created an issue

If the user path contains a space, several SFDX commands will fail on Windows, most notably project creation. Push / pull usually works.

Example:

C:\Users\Jim Work\ as the user path will trigger this error during project creation:

Error running the Salesforce CLI: 'C:\Users\Jim' is not recognized as an internal or external command,operable program or batch file.

This could also be any space in a project path. When creating new scratch orgs this error also happens, even if the current project path is C:\sfdx_projects\example


This may be a bug in other platforms as well which also need special escape handling for spaced paths.

Comments (12)

  1. Scott Wells repo owner

    Matthew, is the issue here with a space in the path to the Salesforce CLI executable? a space in the path to the project directory? both? I'm guessing it's the project directory as my Salesforce CLI path is already C:\Program Files\sfdx\bin\sfdx.cmd.

  2. Scott Wells repo owner

    I've tried this with a CLI path with a space and a project path with a space without issues (aside from some in 2021.2 for which I have local fixes coming). Can you please elaborate on the exact paths with spaces that are causing issues?

  3. Matthew Gladman reporter

    I think it’s primarily caused by the path in the User path having a space. This was on 2020.3 (and IC2 2.1.8.3) so maybe it only applies to that? But I feel like this probably shouldn’t make a difference…

    Here’s a video showing the issue if that helps:

    https://www.youtube.com/watch?v=_pECwfMks78 (I don’t know why there is a hissing sound, so I recommend to mute 🙂)


    Relevant paths in that video:

    > where sfdx
    C:\Program Files\Salesforce CLI\bin\sfdx
    C:\Program Files\Salesforce CLI\bin\sfdx.cmd
    

    Project Path:

    C:\Users\Matt Work\IdeaProjects\example
    

    IC2 Path:

    C:\Users\Matt Work\AppData\Roaming\JetBrains\IntelliJIdea2020.3\plugins\IlluminatedCloud2\lib
    

    If there’s any other paths you think would help, let me know! I think an easy way to replicate the issue is to create a new windows User Scott Wells and then try and create a new SFDX project.

  4. Scott Wells repo owner

    Hmmmm...I'm still unable to reproduce it. The Salesforce CLI is installed at the same path for me:

    $ where sfdx
    C:\Program Files\sfdx\bin\sfdx
    C:\Program Files\sfdx\bin\sfdx.cmd
    

    and I've successfully created multiple projects with spaces in the path, e.g.:

    C:\Users\Scott\dev\projects\Issue 1935\issue_1935
    

    The one difference is that my user home directory itself doesn't have a space in it, so perhaps that's it?

    Do you mind enabling debug logging for Salesforce DX, reproducing the issue, and either attaching or emailing (support@illuminatedcloud.com) the resulting idea.log for review? That should show the exact command-line that's being executed and how/why it's failing.

  5. Matthew Gladman reporter

    I wasn’t aware of the debug flags before, handy!

    2021-08-03 08:45:52,642 [ 722912]  DEBUG - atedcloud.util.CommandLineUtil - Running command line: 'C:/Program Files/sfdx/bin/sfdx.exe force:project:create -d C:/Users/Matt Work/IdeaProjects -n example3 -p force-app -t standard --json' from working directory: 'C:\Users\Matt Work\IdeaProjects\example3'. 
    2021-08-03 08:45:52,647 [ 722917]  DEBUG - .VariableLengthPollingInterval - C:/Program Files/sfdx/bin/sfdx.exe force:project:create -d C:/Users/Matt Work/IdeaProjects -n example3 -p force-app -t standard --json: Using polling interval 1000 ms for polling iteration 1. 
    2021-08-03 08:45:53,659 [ 723929]  DEBUG - atedcloud.util.CommandLineUtil - Returning command-line response: CommandLineResponse{exitCode=1, output='', error=''C:\Users\Matt' is not recognized as an internal or external command,operable program or batch file.', duration=1017} 
    

    That’s the most relevant lines, I’ll email the fuller log to the email, although I don’t think the rest is particularly helpful


    Also, just in case it was an issue, I upgraded to IC 2.1.8.7 and IDEA 2021.1.3 (skipping 2021.2 due to known issues as of writing), no apparent change.


    It also looks like the logging joins each of the array params with a space, so it’s hard to tell where the split is happening for exec, maybe the log should join using , instead of using just a space…

  6. Scott Wells repo owner

    Matt, I just sent this via email as well, but I'll include it here as part of the official discussion on this issue:

    Here's something that confuses me:

    Running command line: 'C:/Program Files/sfdx/bin/sfdx.exe force:project:create -d C:/Users/Matt Work/IdeaProjects -n example3 -p force-app -t standard --json' from working directory: 'C:\Users\Matt Work\IdeaProjects\example3'.
    

    What is sfdx.exe? The executable for the Windows distribution should be sfdx.cmd:

    dir "C:\Program Files\sfdx\bin"
     Volume in drive C is Local Disk
     Volume Serial Number is 6C43-48F3
    
     Directory of C:\Program Files\sfdx\bin
    
    05/11/2021  10:02 AM    <DIR>          .
    05/11/2021  10:02 AM    <DIR>          ..
    04/29/2021  03:50 PM               121 sfdx
    04/29/2021  03:50 PM               242 sfdx.cmd
                   2 File(s)            363 bytes
                   2 Dir(s)  121,693,536,256 bytes free
    

    How is your CLI registered with IC2 in the Salesforce DX application-level configuration tab? The path for mine is C:/Program Files/sfdx/bin/sfdx.cmd.

  7. Matthew Gladman reporter

    Interesting:

    I didn’t manually set the path, it was automatic. I’ll try swapping it for the `cmd` variant instead.

  8. Matthew Gladman reporter

    Well, that stopped the issue from happening immediately. Looks like things don’t get properly translated when using the exe variant instead of the cmd.

    Maybe a warning should be added if the exe variant is used? I’m also not sure how the path was set… (also interestingly you don’t have the exe at all, maybe it was only on old sfdx distributions)

  9. Scott Wells repo owner

    I'm curious about where that sfdx.exe file came from. A fresh installation on Windows--at least in my experience--doesn't include it. IC2 looks for the executable named sfdx in the path, so I can see why it might order the .exe before the .cmd. What I don't understand is what placed the .exe there to start... Good to know that changing to the .cmd file fixed it up, though.

  10. Scott Wells repo owner

    Resolving this but may research the source of that sfdx.exe file and, if it might show up intermittently, I'll have IC2 prefer the .cmd when both are present.

  11. Matthew Gladman reporter

    I suspect it was in the SFDX distribution a while back - the created date was 2017, before .cmd and the non-extension versions were installed on my machine (2018). So I suspect only older installations will be affected 😕

    Maybe it was only in the beta, I was in the beta program a while, so it could be from that, or maybe just the early versions. Not sure… I would check my work machine but that’s been offline during lockdown for a bit.

  12. Log in to comment