// open a file
let result = opener::open(std::path::Path::new("Cargo.toml"));
println!("{:?}", result); // for viewing errors if any captured in the variable result
// to open the file using the default application
open::that("Cargo.toml");
// if you want to open the file with a specific program you should use the following
open::with("Cargo.toml", "notepad");
Python的} 的包装器。你可以call this function via the ^{} crate
os.startfile()
函数仅在Windows上可用,它只是Windows API中^{一个更简单、更可移植的解决方案是使用^{} crate
到目前为止,有两种方法可以在多个操作系统平台(Mac、Windows和Linux)上工作。我也亲自测试过。
方法1: 使用
opener
板条箱(link) 在Windows上使用ShellExecuteW
Windows API函数。在Mac上使用系统open
命令。在其他平台上,使用xdg-open
脚本。系统xdg-open
未使用;相反,此库中嵌入了一个版本。在
rs file
(src/main.rs
)中使用以下代码:在依赖项部分的“Cargo.toml”文件中使用以下代码:
方法2: 使用
open
板条箱(link) 使用此库可以使用系统上配置的程序打开路径或URL。它相当于运行以下操作之一:open <path-or-url>
(OSX),start <path-or-url>
(Windows),xdg-open <path-or-url> || gio open <path-or-url> || gnome-open <path-or-url> || kde-open <path-or-url> || wslview <path-or-url>
(Linux)。在
rs file
(src/main.rs
)中使用以下代码:在依赖项部分的“Cargo.toml”文件中使用以下代码:
希望它对所有人都有效
相关问题 更多 >
编程相关推荐