@@ -25,7 +25,6 @@ pub struct ExecProcessRequest {
2525 args : Option < Vec < String > > ,
2626 cwd : Option < String > ,
2727 env : Option < std:: collections:: HashMap < String , String > > ,
28- shell : Option < String > ,
2928 timeout : Option < u64 > ,
3029}
3130
@@ -92,32 +91,22 @@ pub async fn exec_process(
9291 State ( state) : State < Arc < AppState > > ,
9392 Json ( req) : Json < ExecProcessRequest > ,
9493) -> Result < Json < ApiResponse < ExecProcessResponse > > , AppError > {
95- let mut cmd = if let Some ( shell) = & req. shell {
96- let mut c = Command :: new ( shell) ;
97- c. arg ( "-c" ) ;
98- let mut cmd_str = req. command . clone ( ) ;
99- if let Some ( args) = & req. args {
100- for arg in args {
101- cmd_str. push ( ' ' ) ;
102- cmd_str. push_str ( & crate :: utils:: common:: shell_escape ( arg) ) ;
103- }
104- }
105- c. arg ( cmd_str) ;
94+ let mut cmd = if let Some ( args) = & req. args {
95+ let mut c = Command :: new ( & req. command ) ;
96+ c. args ( args) ;
10697 c
10798 } else {
108- if let Some ( args) = & req. args {
109- let mut c = Command :: new ( & req. command ) ;
110- c. args ( args) ;
111- c
112- } else {
113- let parts: Vec < & str > = req. command . split_whitespace ( ) . collect ( ) ;
114- if parts. len ( ) > 1 {
115- let mut c = Command :: new ( parts[ 0 ] ) ;
116- c. args ( & parts[ 1 ..] ) ;
117- c
118- } else {
119- Command :: new ( & req. command )
99+ match shell_words:: split ( & req. command ) {
100+ Ok ( parts) => {
101+ if !parts. is_empty ( ) {
102+ let mut c = Command :: new ( & parts[ 0 ] ) ;
103+ c. args ( & parts[ 1 ..] ) ;
104+ c
105+ } else {
106+ Command :: new ( & req. command )
107+ }
120108 }
109+ Err ( _) => Command :: new ( & req. command ) ,
121110 }
122111 } ;
123112
@@ -407,7 +396,6 @@ pub struct SyncExecutionRequest {
407396 args : Option < Vec < String > > ,
408397 cwd : Option < String > ,
409398 env : Option < std:: collections:: HashMap < String , String > > ,
410- shell : Option < String > ,
411399 timeout : Option < u64 > ,
412400}
413401
@@ -434,24 +422,23 @@ pub async fn exec_process_sync(
434422 ) ;
435423 let start_instant = std:: time:: Instant :: now ( ) ;
436424
437- let mut cmd = if let Some ( shell) = & req. shell {
438- let mut c = Command :: new ( shell) ;
439- c. arg ( "-c" ) ;
440- let mut cmd_str = req. command . clone ( ) ;
441- if let Some ( args) = & req. args {
442- for arg in args {
443- cmd_str. push ( ' ' ) ;
444- cmd_str. push_str ( & crate :: utils:: common:: shell_escape ( arg) ) ;
445- }
446- }
447- c. arg ( cmd_str) ;
425+ let mut cmd = if let Some ( args) = & req. args {
426+ let mut c = Command :: new ( & req. command ) ;
427+ c. args ( args) ;
448428 c
449429 } else {
450- let mut c = Command :: new ( & req. command ) ;
451- if let Some ( args) = & req. args {
452- c. args ( args) ;
430+ match shell_words:: split ( & req. command ) {
431+ Ok ( parts) => {
432+ if !parts. is_empty ( ) {
433+ let mut c = Command :: new ( & parts[ 0 ] ) ;
434+ c. args ( & parts[ 1 ..] ) ;
435+ c
436+ } else {
437+ Command :: new ( & req. command )
438+ }
439+ }
440+ Err ( _) => Command :: new ( & req. command ) ,
453441 }
454- c
455442 } ;
456443
457444 if let Some ( cwd) = req. cwd {
@@ -539,7 +526,6 @@ pub struct SyncStreamExecutionRequest {
539526 args : Option < Vec < String > > ,
540527 cwd : Option < String > ,
541528 env : Option < std:: collections:: HashMap < String , String > > ,
542- shell : Option < String > ,
543529 timeout : Option < u64 > ,
544530}
545531
@@ -577,24 +563,23 @@ pub async fn exec_process_sync_stream(
577563 ) ) )
578564 . await ;
579565
580- let mut cmd = if let Some ( shell) = & req_for_task. shell {
581- let mut c = Command :: new ( shell) ;
582- c. arg ( "-c" ) ;
583- let mut cmd_str = req_for_task. command . clone ( ) ;
584- if let Some ( args) = & req_for_task. args {
585- for arg in args {
586- cmd_str. push ( ' ' ) ;
587- cmd_str. push_str ( & crate :: utils:: common:: shell_escape ( arg) ) ;
588- }
589- }
590- c. arg ( cmd_str) ;
566+ let mut cmd = if let Some ( args) = & req_for_task. args {
567+ let mut c = Command :: new ( & req_for_task. command ) ;
568+ c. args ( args) ;
591569 c
592570 } else {
593- let mut c = Command :: new ( & req_for_task. command ) ;
594- if let Some ( args) = & req_for_task. args {
595- c. args ( args) ;
571+ match shell_words:: split ( & req_for_task. command ) {
572+ Ok ( parts) => {
573+ if !parts. is_empty ( ) {
574+ let mut c = Command :: new ( & parts[ 0 ] ) ;
575+ c. args ( & parts[ 1 ..] ) ;
576+ c
577+ } else {
578+ Command :: new ( & req_for_task. command )
579+ }
580+ }
581+ Err ( _) => Command :: new ( & req_for_task. command ) ,
596582 }
597- c
598583 } ;
599584
600585 if let Some ( cwd) = & req_for_task. cwd {
0 commit comments