on master help sign in
Fix pager process execution under 'windows'

## [why] For 'windows' platforms, directly spawning a process (eg, called PATHNAME) bypasses the usual windows shell machinery for determining which process to execute. Specifically, the extensions in PATHEXT will not be used to determine the final executable. So, `PATHNAME.bat`, `PATHNAME.cmd`, ... will *not* be executed even if on they exist on the PATH; and this is counter to the usual expectation of a Windows user. Additionally, built-in commands, such as `echo` and `dir`, will never be accessible as they do not have a PATH to execute and, so, will never be found. To use the usual machinery, giving access to PATHNAME.bat and `echo`, execute the PATHNAME using the windows shell, eg `cmd /d/c PATHNAME`. Note this may expose the constructed command line to the windows shell quoting vagaries (sadly, that may be part of the price). Following Windows standards, the ComSpec environment variable is used to determine which shell to use, with a fallback to the "modern", built-in `cmd` shell.

commita2c09b41bc2e6a586310fd72d76ca1d14f95fbeb authorRoy Ivy III <rivy.dev@gmail.com> dateWed 27 May 2020, 21:58 (6 years ago) parent0ef792a
1 file changed+11−2
src/output.rs+11−2
src/output.rs+11−2
@@ -74,8 +74,18 @@ impl OutputType {
7474
7575 let is_less = pager_path.file_stem() == Some(&OsString::from("less"));
7676
77+ #[cfg(windows)]
78+ let (pager_path, args) = {
79+ let p = std::env::var("ComSpec").unwrap_or_else(|_| "cmd".to_string());
80+ let mut a = args.to_vec();
81+ a.insert(0, pager_path.to_str().unwrap().to_string());
82+ a.insert(0, "/d/c".to_string());
83+ (p, a)
84+ };
85+
86+ let mut p = Command::new(&pager_path);
87+
7788 let mut process = if is_less {
78− let mut p = Command::new(&pager_path);
7989 if args.is_empty() || replace_arguments_to_less {
8090 p.arg("--RAW-CONTROL-CHARS");
8191 if quit_if_one_screen {
@@ -106,7 +116,6 @@ impl OutputType {
106116 p.env("LESSCHARSET", "UTF-8");
107117 p
108118 } else {
109− let mut p = Command::new(&pager_path);
110119 p.args(args);
111120 p
112121 };