mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37: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:
parent
f72fff7b42
commit
9dc31cc1ce
1 changed files with 12 additions and 2 deletions
14
src/env/env.rs
vendored
14
src/env/env.rs
vendored
|
@ -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 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let mut core_opts = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP);
|
let mut core_opts = new_coreopts!(SYNTAX, SUMMARY, LONG_HELP);
|
||||||
core_opts
|
core_opts
|
||||||
|
@ -198,8 +209,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !opts.program.is_empty() {
|
if !opts.program.is_empty() {
|
||||||
let prog = opts.program[0].clone();
|
let (prog, args) = build_command(opts.program);
|
||||||
let args = &opts.program[1..];
|
|
||||||
match Command::new(prog).args(args).status() {
|
match Command::new(prog).args(args).status() {
|
||||||
Ok(exit) => {
|
Ok(exit) => {
|
||||||
return if exit.success() {
|
return if exit.success() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue