1
- #![ feature( old_io) ]
2
1
//! Use this library to open a path or URL using the program configured on the system.
3
2
//!
4
3
//! # Usage
19
18
//! As an operating system program is used, chances are that the open operation fails.
20
19
//! Therfore, you are advised to at least check the result with `.is_err()` and
21
20
//! behave accordingly, e.g. by letting the user know what you tried to open, and failed.
22
- use std:: old_io :: IoResult ;
23
- use std:: old_io :: process:: { Command , ProcessExit } ;
21
+ use std:: io ;
22
+ use std:: process:: { Command , ExitStatus } ;
24
23
25
24
#[ cfg( not( any( target_os = "windows" , target_os = "macos" ) ) ) ]
26
- pub fn that ( path : & str ) -> IoResult < ProcessExit > {
27
- use std:: old_io:: IoError ;
28
-
29
- let mut res = Err ( IoError :: from_errno ( 0 , false ) ) ;
25
+ pub fn that ( path : & str ) -> io:: Result < ExitStatus > {
26
+ let mut last_err: io:: Result < ExitStatus > = Err ( io:: Error :: from_raw_os_error ( 0 ) ) ;
30
27
for program in & [ "xdg-open" , "gnome-open" , "kde-open" ] {
31
- res = Command :: new ( program) . arg ( path) . detached ( ) . status ( ) ;
32
- match res {
33
- Ok ( _) => return res,
34
- Err ( _) => continue ,
28
+ match Command :: new ( program) . arg ( path) . spawn ( ) {
29
+ Ok ( mut child) => return child. wait ( ) ,
30
+ Err ( err) => {
31
+ last_err = Err ( err) ;
32
+ continue ;
33
+ } ,
35
34
}
36
35
}
37
- res
36
+ last_err
38
37
}
39
38
40
39
#[ cfg( target_os = "windows" ) ]
41
- pub fn that ( path : & str ) -> IoResult < ProcessExit > {
42
- Command :: new ( "start" ) . arg ( path) . detached ( ) . status ( )
40
+ pub fn that ( path : & str ) -> io:: Result < ExitStatus > {
41
+ match Command :: new ( "start" ) . arg ( path) . spawn ( ) {
42
+ Ok ( mut child) => child. wait ( ) ,
43
+ Err ( err) => Err ( err) ,
44
+ }
43
45
}
44
46
45
47
#[ cfg( target_os = "macos" ) ]
46
- pub fn that ( path : & str ) -> IoResult < ProcessExit > {
47
- Command :: new ( "open" ) . arg ( path) . detached ( ) . status ( )
48
+ pub fn that ( path : & str ) -> io:: Result < ExitStatus > {
49
+ match Command :: new ( "open" ) . arg ( path) . spawn ( ) {
50
+ Ok ( mut child) => child. wait ( ) ,
51
+ Err ( err) => Err ( err) ,
52
+ }
48
53
}
0 commit comments