| 109 | } |
| 110 | |
| 111 | fn read_with_command(program: &str, args: &[&str]) -> anyhow::Result<String> { |
| 112 | let output = Command::new(program) |
| 113 | .args(args) |
| 114 | .output() |
| 115 | .with_context(|| format!("failed to execute clipboard read command: {program}"))?; |
| 116 | |
| 117 | if !output.status.success() { |
| 118 | anyhow::bail!( |
| 119 | "clipboard read command `{}` failed with status {}", |
| 120 | program, |
| 121 | output.status |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | Ok(String::from_utf8_lossy(&output.stdout).to_string()) |
| 126 | } |
| 127 | |
| 128 | fn write_with_command(program: &str, args: &[&str], text: &str) -> anyhow::Result<()> { |
| 129 | let mut child = Command::new(program) |