@@ -370,7 +370,7 @@ use tar::Archive;
370
370
use flate2:: read:: GzDecoder ;
371
371
use flate2:: Compression ;
372
372
use flate2:: write:: GzEncoder ;
373
- use super :: arg:: { execute_command, execute_other_command, split, Commands } ;
373
+ use super :: arg:: { execute_command, execute_other_command, split, stdout_other , Commands } ;
374
374
375
375
376
376
pub fn zxvf ( file : & str , to : & str ) -> Result < ( usize , String ) , std:: io:: Error > {
@@ -398,11 +398,23 @@ pub fn xvf(to: &str) -> Result<(usize,String),std::io::Error>{
398
398
399
399
400
400
// 重定向输出 >
401
+ #[ allow( unused_variables) ]
402
+ #[ allow( unused_assignments) ]
401
403
pub fn stdout_file ( commands : Commands , session_context : & mut SessionContext ) -> Result < ( usize , String ) , std:: io:: Error > {
402
- let command = commands. command . clone ( ) ;
403
- let arg = commands. arg . clone ( ) ;
404
- let result = execute_command ( & command, "" , & arg, session_context) ?. 1 ;
405
- let mut file = File :: create ( arg[ arg. len ( ) -1 ] . clone ( ) ) ?;
404
+ let mut command = commands. command . clone ( ) ;
405
+ let mut option = String :: new ( ) ;
406
+ let mut arg = commands. arg . clone ( ) ;
407
+ let mut file = String :: new ( ) ;
408
+ if command. is_empty ( ) {
409
+ let ( f, new_command) = stdout_other ( & arg) ;
410
+ file = f;
411
+ let ( command_v, option_v, arg_v) = split ( new_command) ;
412
+ ( command, option, arg) = ( command_v, option_v, arg_v) ;
413
+ } else {
414
+ file = arg[ arg. len ( ) -1 ] . clone ( ) ;
415
+ }
416
+ let result = execute_command ( & command, & option, & arg, session_context) ?. 1 ;
417
+ let mut file = File :: create ( file) ?;
406
418
file. write ( result. as_bytes ( ) ) ?;
407
419
Ok ( ( STATUE_CODE , "write over!" . to_string ( ) ) )
408
420
}
0 commit comments