Skip to content

Commit 7d314fc

Browse files
author
梶塚太智
committed
Update main.rs
Become cross-platform compatible
1 parent 4f5dcca commit 7d314fc

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/main.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,9 +866,20 @@ impl Executor {
866866

867867
// ファイルを開く
868868
"open" => {
869-
let _result = std::process::Command::new("cmd")
870-
.args(&["/C", "start", "", self.pop_stack().get_string().as_str()])
871-
.spawn();
869+
if cfg!(target_os = "windows") {
870+
let _result = std::process::Command::new("cmd")
871+
.args(&["/C", "start", "", self.pop_stack().get_string().as_str()])
872+
.spawn();
873+
} else if cfg!(target_os = "linux") {
874+
let _result =
875+
std::process::Command::new("xdg-open") // Linuxの場合
876+
.arg(self.pop_stack().get_string().as_str())
877+
.spawn();
878+
} else if cfg!(target_os = "macos") {
879+
let _result = std::process::Command::new("open")
880+
.arg(self.pop_stack().get_string().as_str())
881+
.spawn();
882+
}
872883
}
873884

874885
// シェルコマンドを実行

0 commit comments

Comments
 (0)