@@ -251,7 +251,7 @@ impl ExecuteResult {
251251/// Reader side of a pipe.
252252#[ derive( Debug ) ]
253253pub enum ShellPipeReader {
254- OsPipe ( os_pipe :: PipeReader ) ,
254+ OsPipe ( std :: io :: PipeReader ) ,
255255 StdFile ( std:: fs:: File ) ,
256256}
257257
@@ -266,10 +266,32 @@ impl Clone for ShellPipeReader {
266266
267267impl ShellPipeReader {
268268 pub fn stdin ( ) -> ShellPipeReader {
269- ShellPipeReader :: from_raw ( os_pipe:: dup_stdin ( ) . unwrap ( ) )
269+ #[ cfg( unix) ]
270+ pub fn dup_stdin_as_pipe_reader ( ) -> std:: io:: PipeReader {
271+ use std:: os:: fd:: AsFd ;
272+ use std:: os:: fd:: IntoRawFd ;
273+ use std:: os:: fd:: FromRawFd ;
274+ let owned = std:: io:: stdin ( ) . as_fd ( ) . try_clone_to_owned ( ) . unwrap ( ) ;
275+ let raw = owned. into_raw_fd ( ) ; // transfer ownership
276+ // SAFETY: `raw` is a fresh, owned fd; PipeReader will close it.
277+ unsafe { std:: io:: PipeReader :: from_raw_fd ( raw) }
278+ }
279+
280+ #[ cfg( windows) ]
281+ pub fn dup_stdin_as_pipe_reader ( ) -> io:: Result < PipeReader > {
282+ use std:: os:: windows:: io:: AsHandle ;
283+ use std:: os:: windows:: io:: IntoRawHandle ;
284+ use std:: os:: windows:: io:: FromRawHandle ;
285+ let owned = io:: stdin ( ) . as_handle ( ) . try_clone_to_owned ( ) . unwrap ( ) ;
286+ let raw = owned. into_raw_handle ( ) ; // transfer ownership
287+ // SAFETY: `raw` is a fresh, owned HANDLE; PipeReader will close it.
288+ unsafe { std:: io:: PipeReader :: from_raw_handle ( raw) }
289+ }
290+
291+ ShellPipeReader :: OsPipe ( dup_stdin_as_pipe_reader ( ) )
270292 }
271293
272- pub fn from_raw ( reader : os_pipe :: PipeReader ) -> Self {
294+ pub fn from_raw ( reader : std :: io :: PipeReader ) -> Self {
273295 Self :: OsPipe ( reader)
274296 }
275297
@@ -281,7 +303,7 @@ impl ShellPipeReader {
281303 #[ allow( clippy:: should_implement_trait) ]
282304 pub fn from_str ( data : & str ) -> Self {
283305 use std:: io:: Write ;
284- let ( read, mut write) = os_pipe :: pipe ( ) . unwrap ( ) ;
306+ let ( read, mut write) = std :: io :: pipe ( ) . unwrap ( ) ;
285307 write. write_all ( data. as_bytes ( ) ) . unwrap ( ) ;
286308 Self :: OsPipe ( read)
287309 }
@@ -369,7 +391,7 @@ impl ShellPipeReader {
369391/// prevent deadlocks where the reader hangs waiting for a read.
370392#[ derive( Debug ) ]
371393pub enum ShellPipeWriter {
372- OsPipe ( os_pipe :: PipeWriter ) ,
394+ OsPipe ( std :: io :: PipeWriter ) ,
373395 StdFile ( std:: fs:: File ) ,
374396 // For stdout and stderr, instead of directly duplicating the raw pipes
375397 // and putting them in a ShellPipeWriter::OsPipe(...), we use Rust std's
@@ -468,7 +490,7 @@ impl ShellPipeWriter {
468490
469491/// Used to communicate between commands.
470492pub fn pipe ( ) -> ( ShellPipeReader , ShellPipeWriter ) {
471- let ( reader, writer) = os_pipe :: pipe ( ) . unwrap ( ) ;
493+ let ( reader, writer) = std :: io :: pipe ( ) . unwrap ( ) ;
472494 (
473495 ShellPipeReader :: OsPipe ( reader) ,
474496 ShellPipeWriter :: OsPipe ( writer) ,
0 commit comments