This commit is contained in:
parent
cd78f76aff
commit
b602c1293b
@ -1091,10 +1091,6 @@ fn write_cmds(cmds: String, ext: &str) -> ResultType<std::path::PathBuf> {
|
|||||||
cmds.as_ptr(),
|
cmds.as_ptr(),
|
||||||
ext
|
ext
|
||||||
));
|
));
|
||||||
let mut cmds = cmds;
|
|
||||||
if ext == "cmd" {
|
|
||||||
cmds = format!("{}\ndel /f \"{}\"", cmds, tmp.to_str().unwrap_or(""));
|
|
||||||
}
|
|
||||||
let mut file = std::fs::File::create(&tmp)?;
|
let mut file = std::fs::File::create(&tmp)?;
|
||||||
// in case cmds mixed with \r\n and \n, make sure all ending with \r\n
|
// in case cmds mixed with \r\n and \n, make sure all ending with \r\n
|
||||||
// in some windows, \r\n required for cmd file to run
|
// in some windows, \r\n required for cmd file to run
|
||||||
@ -1118,14 +1114,19 @@ fn to_le(v: &mut [u16]) -> &[u8] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_cmds(cmds: String, show: bool) -> ResultType<()> {
|
fn run_cmds(cmds: String, show: bool) -> ResultType<()> {
|
||||||
let tmp = write_cmds(cmds, "cmd")?;
|
let tmp = write_cmds(cmds, "bat")?;
|
||||||
let res = runas::Command::new(tmp.to_str().unwrap_or(""))
|
let tmp_fn = tmp.to_str().unwrap_or("");
|
||||||
|
let res = runas::Command::new("cmd")
|
||||||
|
.args(&["/C", &tmp_fn])
|
||||||
.show(show)
|
.show(show)
|
||||||
.force_prompt(true)
|
.force_prompt(true)
|
||||||
.status();
|
.status();
|
||||||
// double confirm delete, because below delete not work if program
|
// leave the file for debug if execution failed
|
||||||
// exit immediately such as --uninstall
|
if let Ok(res) = res {
|
||||||
allow_err!(std::fs::remove_file(tmp));
|
if res.success() {
|
||||||
|
allow_err!(std::fs::remove_file(tmp));
|
||||||
|
}
|
||||||
|
}
|
||||||
let _ = res?;
|
let _ = res?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user