1

I am looking for a short command which I can execute in the Windows 10 command shell (cmd) or in powershell or in git-bash for Windows, which would replace PATH Environment variable items to double quote those which have spaces?

The actual problem I face is that when I type a command in git-bash

$ sfdx force:org:create -s -f config/project-scratch-def.json -a "default scratch org"

I receive an error

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

enter image description here I think this error happens because sfdx tool is located in "C:\Program Files\Salesforce CLI\bin" and it should be probably double quoted in path if I am not wrong.

So when I execute path command in cmd I see

D:\Git\SFDX\MySFDXProject>path
PATH=C:\Python27\;C:\Ruby23\bin;C:\Program Files\Salesforce CLI\bin

so I guess C:\Program Files\Salesforce CLI\bin should be double quoted in path but I want mass double quote any path items which have spaces in path so that any other command won't fail.

So if my path is C:\Python27\;C:\Ruby23\bin;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Salesforce CLI\bin I want it to be transformed by command into C:\Python27\;C:\Ruby23\bin;"C:\Program Files\Microsoft VS Code\bin";"C:\Program Files\Salesforce CLI\bin" and to be saved in PATH environment variable.

How do I do that?

5
  • PATH uses semicolons as delimiters, so quotation marks are not necessary. My PATH is filled with lots of folders that contain spaces. My guess is that there is some other environment variable that needs quotation marks. I'm not familiar with what "sfdx" is, so I can't help further pinpoint your problem. Commented Jun 14, 2018 at 18:09
  • You have a syntax error in your system variable. To determine which path is causing the problem. Restore the default system variable value, and one by one, add the additional paths you need. Be sure you are not reaching the length limit for the variable either.
    – Ramhound
    Commented Jun 14, 2018 at 18:19
  • Bill is right.. It might be something your sfdx command is doing. Also see developer.salesforce.com/forums/?id=9060G0000005b4zQAA it says to try- $sfdx force:org:create -f project-scratch-def.json -a MyScratchOrg<ENTER>
    – barlop
    Commented Jun 14, 2018 at 18:36
  • bash does not use the same path format as Windows. See stackoverflow.com/questions/13701218/…
    – DavidPostill
    Commented Jun 14, 2018 at 19:14
  • Ok, when I run that command in default windows "CMD" command line, it works, but when I run that command in "git bash" windows shell, it doesn't work. So I guess if I had every path item member doublequoted, it should have worked
    – Patlatus
    Commented Jun 18, 2018 at 8:07

1 Answer 1

0

Create a file which changes the path, creates a child process, calls the sfdx command in the child process, and prints out the result. For example:

// env-change.js
process.env.path=process.env.path.replace(/Program Files/g,'"Program Files"');
const { exec } = require('child_process');

function result(err, stdout, stderr){
  if (err) {
    console.error(err);
    return;
  }
  console.log(stdout);
  console.log(process.env.path);
}

exec('sfdx force:org:create -s -f config/project-scratch-def.json -a "default scratch org"', result);

Then run it like so:

node env-change.js

References

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .