+1
-1
@@ -15,3 +15,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "doe" | ||
| version = "1.1.72" | ||
| version = "1.1.73" | ||
| authors = ["Andrew <dnrops@outlook.com>"] | ||
@@ -18,0 +18,0 @@ build = false |
+50
-0
@@ -767,1 +767,51 @@ #![deny(rust_2018_idioms)] | ||
| #[derive(Debug,Clone,Default)] | ||
| /// CommandResult | ||
| pub struct CommandResult { | ||
| #[allow(dead_code)] | ||
| ///stderr | ||
| pub stderr: Box<str>, | ||
| #[allow(dead_code)] | ||
| ///stderr_size | ||
| pub stdout: Box<str>, | ||
| ///executed | ||
| pub executed: bool, | ||
| /// status | ||
| pub status: bool, | ||
| } | ||
| /// max_cmd_output_size | ||
| pub const MAX_CMD_OUTPUT_SIZE: usize = 1 << 15; | ||
| /// execute_command | ||
| /// | ||
| /// ```ignore | ||
| /// use doe::execute_command; | ||
| /// let result = execute_command("nasm".as_ref(), &["-version".as_ref()]); | ||
| /// println!("{:?}",result); | ||
| /// ``` | ||
| /// | ||
| /// | ||
| pub fn execute_command(executable: &std::ffi::OsStr, args: &[&std::ffi::OsStr]) -> CommandResult { | ||
| if let std::result::Result::Ok(mut result) = std::process::Command::new(executable).args(args).output() { | ||
| result.stderr.truncate(MAX_CMD_OUTPUT_SIZE); | ||
| let stderr = String::from_utf8(result.stderr) | ||
| .unwrap_or_default() | ||
| .into_boxed_str(); | ||
| result.stdout.truncate(MAX_CMD_OUTPUT_SIZE); | ||
| let stdout = String::from_utf8(result.stdout) | ||
| .unwrap_or_default() | ||
| .into_boxed_str(); | ||
| return CommandResult { | ||
| stderr, | ||
| stdout, | ||
| executed: true, | ||
| status: result.status.success(), | ||
| }; | ||
| } | ||
| CommandResult { | ||
| stderr: String::new().into_boxed_str(), | ||
| stdout: String::new().into_boxed_str(), | ||
| executed: false, | ||
| status: false, | ||
| } | ||
| } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet