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

How to Run Commands from and with Paths that have Special Characters like Parenthesis? #4549

Closed
2 tasks done
JuliusPIV opened this issue Mar 6, 2025 · 2 comments
Closed
2 tasks done
Labels
answered 🎉 Yay! The issue has been resolved, or the question has been answered. question windows

Comments

@JuliusPIV
Copy link

JuliusPIV commented Mar 6, 2025

Node.js Version

all versions

NPM Version

all versions

Operating System

Windows 11

Subsystem

Other

Description

Hi All. Apologies in advance as I am not a Software Engineer/Developer and am not a user of node.js, npm/npx, angular, and other related tools. I provide support for the machines used by our Software Engineers/Developers within the organization. As such I'm asking for a little grace here!

TL;DR: When a path contains special characters, specifically open & close parentheses, is it possible to escape those special characters when running npm/npx commands? What do we need to do to escape those special characters before running commands?

Details:
We have a situation in our environment where many Windows user profiles get created with special characters, specifically an open or open and closed parenthesis, due to their user profile directory matching their display name.

  • For example Matt Smith's user profile directory in C:\Users would be "MattSmith(Vendor)".
  • For example Bartholomew Smith's user profile in C:\Users would be "BartholomewSmith(Ve" - its truncated due to the length.

We have a about a hundred if not more people in this state in our environment and when they try to run npm/npx commands (from Visual Studio, VSCode, Webstorm etc.) the process fails presumably due to the parenthesis in the directory name.
npx eslint . --config C:/Users/BartholomewSmith(Ve/Dir1/Dir2/.eslintrc.js --format html --resolve-plugins-relative-to C:/Users/BartholomewSmith(Ve/Dir1/Dir2

I say presumably because in the past when we've "fixed" the user profile name and they re-run the exact same commands, everything works the issue goes away.

Regarding the "fix": Since Windows doesn't support renaming user profiles, the "fix" is a little convoluted from either creating a whole new user profile or rebuilding the machine from scratch. This results in our SEs/Devs having need to reinstall everything making this a very expensive.

For future scenarios we should be able to address this proactively making it a non-issue, but updating their display name before they get setup on their machine. However this isn't always possible which is why we have a number of people in this state today.

Thanks in advance for any guidance you can provide on this.

Minimal Reproduction

Create a user profile on a machine that has at least 1 open parenthesis in their name.
Run an npm/npx command like:
npx eslint . --config C:/Users/BartholomewSmith(Ve/Dir1/Dir2/.eslintrc.js --format html --resolve-plugins-relative-to C:/Users/BartholomewSmith(Ve/Dir1/Dir2

The process fails.

Output

I do not have any safe, sanitized examples to share at this time.

Before You Submit

  • I have looked for issues that already exist before submitting this
  • My issue follows the guidelines in the README file, and follows the 'How to ask a good question' guide at https://stackoverflow.com/help/how-to-ask
@avivkeller
Copy link
Member

avivkeller commented Mar 19, 2025

Certain command-line tools, including npm and npx, won't correctly handle these special characters unless properly escaped or quoted, as they will be seen as quantifiers/operators, rather than a raw string.

1. Quote the Paths (Best Practice)

Always enclose paths with special characters in double quotes ("):

npx eslint . --config "C:/Users/BartholomewSmith(Ve/Dir1/Dir2/.eslintrc.js" --format html --resolve-plugins-relative-to "C:/Users/BartholomewSmith(Ve/Dir1/Dir2"

This is the most reliable approach and should work in most cases.

2. Escape Parentheses in Paths

For command-line environments like PowerShell, escaping parentheses requires backticks (```):

npx eslint . --config C:/Users/BartholomewSmith`(Ve`)/Dir1/Dir2/.eslintrc.js --format html --resolve-plugins-relative-to C:/Users/BartholomewSmith`(Ve`)/Dir1/Dir2

For Command Prompt (cmd.exe), escaping requires carets (^):

npx eslint . --config C:/Users/BartholomewSmith^(Ve^)/Dir1/Dir2/.eslintrc.js --format html --resolve-plugins-relative-to C:/Users/BartholomewSmith^(Ve^)/Dir1/Dir2

@avivkeller avivkeller added windows answered 🎉 Yay! The issue has been resolved, or the question has been answered. labels Mar 20, 2025
@JuliusPIV
Copy link
Author

Brilliant @avivkeller - thank you so much for the detailed responses!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered 🎉 Yay! The issue has been resolved, or the question has been answered. question windows
Projects
None yet
Development

No branches or pull requests

3 participants