0
I am trying to call bcdedit from within a rust executable using std::process::Command.
When executing the resulting program on Windows 10 in an administrator command prompt I get:
'bcdedit' is not recognized as an internal or external command, operable program or batch file.
.
- Calling bcdedit directly in the same shell works just fine.
- Calling it with its absolute path makes no difference.
- Calling other executables works ok.
- Calling bcdedit directly without using cmd.exe returns
error: Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }
.
This happens on Windows 10 Pro, version 1903, Build 18362.657. I have another Windows 10 installed (Windows 10 Pro, version 1809, build 17763.1039) on which this works ok.
I have a rust snippet that exposes the problem:
use std::process::{Command, Stdio};
use std::env::args;
fn main() {
let mut cmd_args = args();
let cmd = if let Some(arg1) = cmd_args.nth(1) {
arg1
} else {
String::from("dir")
};
println!("command is '{}'", cmd);
match Command::new("cmd.exe")
.arg("/c")
.arg(&cmd)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.output() {
Ok(output) => {
println!("Executed '{}', success: {}", cmd, output.status.success());
println!("stdout: '{}'", String::from_utf8_lossy(&output.stdout));
println!("stderr: '{}'", String::from_utf8_lossy(&output.stderr));
}
Err(why) => {
eprintln!("Failed to execute '{}', error: {:?}", &cmd, why);
}
}
}
Msgbox box out the command you are executing. – Mark – 2020-02-19T20:57:12.457
Maybe run Process Monitor, see what's going on? Is it a 32 or 64-bit exe? Does it work %windir%\sysnative\bcdedit.exe for example? – HelpingHand – 2020-02-19T21:12:37.570