1
- use std:: {
2
- ffi:: { OsStr , OsString } ,
3
- io,
4
- os:: windows:: ffi:: OsStrExt ,
5
- ptr,
6
- } ;
1
+ use std:: { ffi:: OsStr , io} ;
7
2
8
- use std:: os:: raw:: c_int;
9
-
10
- use crate :: IntoResult ;
11
-
12
- fn convert_path ( path : & OsStr ) -> io:: Result < Vec < u16 > > {
13
- let mut quoted_path = OsString :: with_capacity ( path. len ( ) ) ;
14
-
15
- // Surround path with double quotes "" to handle spaces in path.
16
- quoted_path. push ( "\" " ) ;
17
- quoted_path. push ( & path) ;
18
- quoted_path. push ( "\" " ) ;
19
-
20
- let mut wide_chars: Vec < _ > = quoted_path. encode_wide ( ) . collect ( ) ;
21
- if wide_chars. iter ( ) . any ( |& u| u == 0 ) {
22
- return Err ( io:: Error :: new (
23
- io:: ErrorKind :: InvalidInput ,
24
- "path contains NUL byte(s)" ,
25
- ) ) ;
26
- }
27
- wide_chars. push ( 0 ) ;
28
- Ok ( wide_chars)
29
- }
3
+ use crate :: { CommandExt , IntoResult } ;
30
4
31
5
pub fn that < T : AsRef < OsStr > > ( path : T ) -> io:: Result < ( ) > {
32
- let path = convert_path ( path. as_ref ( ) ) ?;
33
- Command :: new ( "cmd" )
6
+ std:: process:: Command :: new ( "cmd" )
34
7
. arg ( "/c" )
35
8
. arg ( "start" )
36
9
. arg ( path. as_ref ( ) )
@@ -39,8 +12,7 @@ pub fn that<T: AsRef<OsStr>>(path: T) -> io::Result<()> {
39
12
}
40
13
41
14
pub fn with < T : AsRef < OsStr > > ( path : T , app : impl Into < String > ) -> io:: Result < ( ) > {
42
- let path = convert_path ( path. as_ref ( ) ) ?;
43
- Command :: new ( "cmd" )
15
+ std:: process:: Command :: new ( "cmd" )
44
16
. arg ( "/c" )
45
17
. arg ( app. into ( ) )
46
18
. arg ( path. as_ref ( ) )
0 commit comments