From a130bdc125b073e75687768f47e22dcad2618681 Mon Sep 17 00:00:00 2001 From: finga Date: Mon, 22 Mar 2021 11:12:45 +0100 Subject: [PATCH] Print `stdout` and `stderr` as string As the `stdout` as well as the `stderr` were printed as `Vec` we now convert it to a string. --- src/main.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index d39ddbd..33ae35b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,10 @@ use rocket::{fairing::AdHoc, get, http::Status, post, routes, Response, State}; use rocket_contrib::json::Json; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, fs::File, io::BufReader, net::SocketAddr, process::Command}; +use std::{ + collections::HashMap, fs::File, io::BufReader, net::SocketAddr, process::Command, + str::from_utf8, +}; #[derive(Debug, Deserialize, Serialize)] struct Config { @@ -100,21 +103,21 @@ fn execute_hook(name: &str, hook: &Hook, data: &serde_json::Value) -> Result<()> info!("Execute `{}` from hook `{}`", command, name); let command = command.split(' ').collect::>(); - let exec_command = Command::new(&command[0]).args(&command[1..]).output()?; info!( "Command `{}` exited with return code: {}", &command[0], &exec_command.status ); - debug!( - "Output of command `{}` on stderr: {:?}", - &command[0], &exec_command.stderr - ); trace!( "Output of command `{}` on stdout: {:?}", &command[0], - &exec_command.stdout + from_utf8(&exec_command.stdout)? + ); + debug!( + "Output of command `{}` on stderr: {:?}", + &command[0], + from_utf8(&exec_command.stderr)? ); }