Skip to content

Commit 5607cd6

Browse files
author
ZhuXiaojie
committed
Fix open::with() on Windows. (#80)
1 parent 659b8a0 commit 5607cd6

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/main.rs

+10
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,21 @@ fn main() {
99
}
1010
};
1111

12+
#[cfg(not(windows))]
1213
let result = match std::env::var("OPEN_WITH").ok() {
1314
Some(program) => open::with(&path_or_url, program),
1415
None => open::that(&path_or_url),
1516
};
1617

18+
#[cfg(windows)]
19+
let result = match env::args().nth(2) {
20+
Some(arg) if arg == "--with" || arg == "-w" => match env::args().nth(3) {
21+
Some(program) => open::with(&path_or_url, program),
22+
None => open::that(&path_or_url),
23+
},
24+
_ => open::that(&path_or_url),
25+
};
26+
1727
match result {
1828
Ok(()) => println!("Opened '{}' successfully.", path_or_url),
1929
Err(err) => {

src/windows.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub fn commands<T: AsRef<OsStr>>(path: T) -> Vec<Command> {
2020
pub fn with_command<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> Command {
2121
let mut cmd = Command::new("cmd");
2222
cmd.arg("/c")
23+
.arg("start")
24+
.raw_arg("\"\"")
2325
.raw_arg(app.into())
2426
.raw_arg(wrap_in_quotes(path))
2527
.creation_flags(CREATE_NO_WINDOW);

0 commit comments

Comments
 (0)