@@ -79,15 +79,17 @@ use crate::input::ScriptsRequired;
7979use anyhow:: { anyhow, Result } ;
8080use log:: debug;
8181use serde_derive:: { Deserialize , Serialize } ;
82- use std:: convert:: TryInto ;
8382use std:: fs:: { self , File } ;
8483use std:: io:: { self , prelude:: * } ;
8584use std:: net:: IpAddr ;
8685use std:: path:: PathBuf ;
86+ use std:: process:: { Command , Stdio } ;
8787use std:: string:: ToString ;
88- use subprocess:: { Exec , ExitStatus , Redirection } ;
8988use text_placeholder:: Template ;
9089
90+ #[ cfg( unix) ]
91+ use std:: os:: unix:: process:: ExitStatusExt ;
92+
9193static DEFAULT : & str = r#"tags = ["core_approved", "RustScan", "default"]
9294developer = [ "RustScan", "https://github.com/RustScan" ]
9395ports_separator = ","
@@ -271,21 +273,41 @@ impl Script {
271273#[ cfg( not( tarpaulin_include) ) ]
272274fn execute_script ( script : & str ) -> Result < String > {
273275 debug ! ( "\n Script arguments {}" , script) ;
274- let process = Exec :: shell ( script)
275- . stdout ( Redirection :: Pipe )
276- . stderr ( Redirection :: Pipe ) ;
277- match process. capture ( ) {
278- Ok ( c) => {
279- let es = match c. exit_status {
280- ExitStatus :: Exited ( c) => c. try_into ( ) . unwrap ( ) ,
281- ExitStatus :: Signaled ( c) => c. into ( ) ,
282- ExitStatus :: Other ( c) => c,
283- ExitStatus :: Undetermined => -1 ,
276+
277+ let ( cmd, arg) = if cfg ! ( unix) {
278+ ( "sh" , "-c" )
279+ } else {
280+ ( "cmd.exe" , "/c" )
281+ } ;
282+
283+ match Command :: new ( cmd)
284+ . args ( & [ arg, script] )
285+ . stdin ( Stdio :: piped ( ) )
286+ . stderr ( Stdio :: piped ( ) )
287+ . output ( )
288+ {
289+ Ok ( output) => {
290+ let status = output. status ;
291+
292+ let es = match status. code ( ) {
293+ Some ( code) => code,
294+ _ => {
295+ #[ cfg( unix) ]
296+ {
297+ status. signal ( ) . unwrap ( )
298+ }
299+
300+ #[ cfg( windows) ]
301+ {
302+ return Err ( anyhow ! ( "Unknown exit status" ) ) ;
303+ }
304+ }
284305 } ;
306+
285307 if es != 0 {
286308 return Err ( anyhow ! ( "Exit code = {}" , es) ) ;
287309 }
288- Ok ( c . stdout_str ( ) )
310+ Ok ( String :: from_utf8_lossy ( & output . stdout ) . into_owned ( ) )
289311 }
290312 Err ( error) => {
291313 debug ! ( "Command error {}" , error. to_string( ) ) ;
0 commit comments