1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

env: enhance support for windows commands (BAT/CMD, builtins)

.# Discussion

`env`/`uutils env` didn't support CMD built-in commands (dir, echo, erase, ...),
BAT/CMD files, nor the usual semantics for command search and execution via
PATHEXT (eg, it wouldn't find/execute `batch.BAT` when given just `batch`).

This patch executes the commands via a CMD subshell and fixes all of those issues.
This commit is contained in:
Roy Ivy III 2018-10-06 20:03:27 -05:00
parent f72fff7b42
commit 9dc31cc1ce

14
src/env/env.rs vendored
View file

@ -40,6 +40,17 @@ fn print_env(null: bool) {
}
}
#[cfg(not(windows))]
fn build_command(mut args: Vec<String>) -> (String, Vec<String>) {
(args.remove(0), args)
}
#[cfg(windows)]
fn build_command(mut args: Vec<String>) -> (String, Vec<String>) {
args.insert(0, "/d/c".to_string());
(env::var("ComSpec").unwrap_or("cmd".to_string()), args)
}
pub fn uumain(args: Vec<String>) -> i32 {
let mut core_opts = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP);
core_opts
@ -198,8 +209,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
}
if !opts.program.is_empty() {
let prog = opts.program[0].clone();
let args = &opts.program[1..];
let (prog, args) = build_command(opts.program);
match Command::new(prog).args(args).status() {
Ok(exit) => {
return if exit.success() {