1
1
use std:: io:: Write ;
2
+ use std:: os:: windows:: process:: CommandExt ;
2
3
use std:: process:: { Command , Output , Stdio } ;
3
4
use std:: string:: { FromUtf16Error , FromUtf8Error } ;
4
5
use thiserror:: Error ;
6
+ use windows:: Win32 :: System :: Threading :: CREATE_NO_WINDOW ;
5
7
6
8
#[ derive( Debug ) ]
7
9
pub struct WslDistribution {
@@ -51,6 +53,7 @@ fn to_u16(original: &[u8]) -> Vec<u16> {
51
53
52
54
pub fn get_distributions ( ) -> Result < Vec < WslDistribution > , Error > {
53
55
let output = Command :: new ( "wsl.exe" )
56
+ . creation_flags ( CREATE_NO_WINDOW . 0 )
54
57
. arg ( "--list" )
55
58
. arg ( "--verbose" )
56
59
. output ( ) ?;
@@ -101,6 +104,7 @@ fn check_wsl_output(output: &Output) -> Result<(), Error> {
101
104
impl WslDistribution {
102
105
pub fn read_file ( & self , path : & str ) -> Result < String , Error > {
103
106
let output = Command :: new ( "wsl.exe" )
107
+ . creation_flags ( CREATE_NO_WINDOW . 0 )
104
108
. arg ( "--distribution" )
105
109
. arg ( & self . name )
106
110
. arg ( "--user" )
@@ -115,6 +119,7 @@ impl WslDistribution {
115
119
pub fn set_read_only ( & self , path : & str , read_only : bool ) -> Result < ( ) , Error > {
116
120
let arg = if read_only { "+i" } else { "-i" } ;
117
121
let output = Command :: new ( "wsl.exe" )
122
+ . creation_flags ( CREATE_NO_WINDOW . 0 )
118
123
. arg ( "--distribution" )
119
124
. arg ( & self . name )
120
125
. arg ( "--user" )
@@ -129,6 +134,7 @@ impl WslDistribution {
129
134
130
135
pub fn write_file ( & self , path : & str , contents : & str ) -> Result < ( ) , Error > {
131
136
let mut p = Command :: new ( "wsl.exe" )
137
+ . creation_flags ( CREATE_NO_WINDOW . 0 )
132
138
. stdin ( Stdio :: piped ( ) )
133
139
. stdout ( Stdio :: piped ( ) )
134
140
. stderr ( Stdio :: piped ( ) )
@@ -151,6 +157,7 @@ impl WslDistribution {
151
157
152
158
pub fn terminate ( & self ) -> Result < ( ) , Error > {
153
159
let output = Command :: new ( "wsl.exe" )
160
+ . creation_flags ( CREATE_NO_WINDOW . 0 )
154
161
. arg ( "--terminate" )
155
162
. arg ( & self . name )
156
163
. output ( ) ?;
0 commit comments