Skip to content

Commit b039db7

Browse files
refactor: replace subprocess crate with std::process (#697)
1 parent 8350947 commit b039db7

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

Cargo.lock

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ cidr-utils = "0.6.1"
3737
itertools = "0.13.0"
3838
hickory-resolver = { version = "0.24.0", features = ["dns-over-rustls"] }
3939
anyhow = "1.0.40"
40-
subprocess = "0.2.6"
4140
text_placeholder = { version = "0.5", features = ["struct_context"] }
4241
once_cell = "1.20.2"
4342

src/scripts/mod.rs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,17 @@ use crate::input::ScriptsRequired;
7979
use anyhow::{anyhow, Result};
8080
use log::debug;
8181
use serde_derive::{Deserialize, Serialize};
82-
use std::convert::TryInto;
8382
use std::fs::{self, File};
8483
use std::io::{self, prelude::*};
8584
use std::net::IpAddr;
8685
use std::path::PathBuf;
86+
use std::process::{Command, Stdio};
8787
use std::string::ToString;
88-
use subprocess::{Exec, ExitStatus, Redirection};
8988
use text_placeholder::Template;
9089

90+
#[cfg(unix)]
91+
use std::os::unix::process::ExitStatusExt;
92+
9193
static DEFAULT: &str = r#"tags = ["core_approved", "RustScan", "default"]
9294
developer = [ "RustScan", "https://github.com/RustScan" ]
9395
ports_separator = ","
@@ -271,21 +273,41 @@ impl Script {
271273
#[cfg(not(tarpaulin_include))]
272274
fn execute_script(script: &str) -> Result<String> {
273275
debug!("\nScript 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

Comments
 (0)