dprint-plugin-exec icon indicating copy to clipboard operation
dprint-plugin-exec copied to clipboard

Prefer resolving to PATHEXT extensions on Windows

Open dsherret opened this issue 2 years ago • 1 comments

The command in the config here (https://github.com/dprint/dprint-plugin-exec/issues/23#issuecomment-1464831839):

"exec": {
    "associations": [
      "**/*.{sh,bash}",
      "**/package.json"
    ],
    "prettier-package-json.associations": "**/package.json",
    "prettier-package-json": "node_modules/.bin/prettier-package-json"
  },

...has files prettier-package-json, prettier-package-json.cmd and prettier-package-json.ps1, but doesn't work on Windows:

Error formatting V:\scratch-npm\package.json. Message: Cannot start formatter process: %1 is not a valid Win32 application. (os error 193)

...unless the .cmd extension is provided. It should work cross platform and not require this extension.

dsherret avatar Mar 11 '23 05:03 dsherret

Ran into this issue while trying to integrate the Dart formatter (the Dart CLI is provided by a dart.bat file). This does seem to be the intended behaviour of Rust's std::process::Command though, due to the associated security concerns (source):

The search path to be used may be controlled by setting the PATH environment variable on the Command, but this has some implementation limitations on Windows (see issue https://github.com/rust-lang/rust/issues/37519).

Platform-specific behavior

Note on Windows: For executable files with the .exe extension, it can be omitted when specifying the program for this Command. However, if the file has a different extension, a filename including the extension needs to be provided, otherwise the file won’t be found.

See also: https://github.com/rust-lang/rust/issues/123728 and https://github.com/rust-lang/rust/issues/94743

One way around this would be to use the which crate, which returns the absolute path to an executable while respecting Windows's PATHEXT environment variable.

mahtaran avatar Jun 05 '25 21:06 mahtaran