diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 17 | 
1 files changed, 12 insertions, 5 deletions
| diff --git a/src/main.rs b/src/main.rs index cf451dd..bc59b0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,12 +14,17 @@ mod config;  const PROGRAM: &str = "mqttr";  async fn run(program: &[String], message: &Publish) -> anyhow::Result<()> { -    // TODO: Set environment variables -    let mut proc = Command::new(&program[0]) +    let mut command = Command::new(&program[0]); +    command          .args(&program[1..])          .arg(&message.topic) -        .stdin(Stdio::piped()) -        .spawn()?; +        .arg(format!("{}", message.dup as u8)) +        .arg(format!("{}", message.qos as u8)) +        .arg(format!("{}", message.retain as u8)); +    if message.qos == QoS::AtLeastOnce || message.qos == QoS::ExactlyOnce { +        command.arg(format!("{}", message.pkid)); +    } +    let mut proc = command.stdin(Stdio::piped()).spawn()?;      let mut stdin = proc.stdin.take().context("No stdin")?;      stdin.write(&message.payload).await?;      drop(stdin); @@ -88,7 +93,9 @@ async fn main() -> anyhow::Result<()> {                          let p = p.clone();                          tokio::spawn(async move {                              match timeout(Duration::from_secs(60), run(&program, &p)).await { -                                Err(_) => eprintln!("error: Execution of {program:?} for message {p:?} timed out"), +                                Err(_) => eprintln!( +                                    "error: Execution of {program:?} for message {p:?} timed out" +                                ),                                  Ok(Err(e)) => eprintln!("error: Failed to run {program:?}: {e:?}"),                                  _ => (),                              } | 
