(program: &str, args: &[&str], text: &str)
| 126 | } |
| 127 | |
| 128 | fn write_with_command(program: &str, args: &[&str], text: &str) -> anyhow::Result<()> { |
| 129 | let mut child = Command::new(program) |
| 130 | .args(args) |
| 131 | .stdin(Stdio::piped()) |
| 132 | .stdout(Stdio::null()) |
| 133 | .stderr(Stdio::null()) |
| 134 | .spawn() |
| 135 | .with_context(|| format!("failed to execute clipboard write command: {program}"))?; |
| 136 | |
| 137 | if let Some(mut stdin) = child.stdin.take() { |
| 138 | stdin.write_all(text.as_bytes()).with_context(|| { |
| 139 | format!("failed to write text to clipboard command stdin: {program}") |
| 140 | })?; |
| 141 | } |
| 142 | |
| 143 | let status = child |
| 144 | .wait() |
| 145 | .with_context(|| format!("failed waiting for clipboard command: {program}"))?; |
| 146 | if !status.success() { |
| 147 | anyhow::bail!( |
| 148 | "clipboard write command `{}` failed with status {}", |
| 149 | program, |
| 150 | status |
| 151 | ); |
| 152 | } |
| 153 | Ok(()) |
| 154 | } |
| 155 | |
| 156 | fn read_raw_with_command(program: &str, args: &[&str]) -> anyhow::Result<Vec<u8>> { |
| 157 | let output = Command::new(program) |
no test coverage detected