Skip to content

Commit e2e2bd4

Browse files
committed
[rust] Error after desktop recording if command terminates
1 parent 2aa491b commit e2e2bd4

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

rust/src/ffmpeg.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ use crate::files::{
2323
};
2424
use crate::lock::Lock;
2525
use crate::logger::Logger;
26-
use crate::shell::Command;
27-
use crate::{
28-
format_four_args, format_one_arg, format_three_args, format_two_args,
29-
run_shell_command_with_log, ENV_DISPLAY,
30-
};
31-
use anyhow::Error;
26+
use crate::shell::{run_shell_command_with_stderr, Command};
27+
use crate::{format_four_args, format_one_arg, format_three_args, format_two_args, ENV_DISPLAY};
28+
use anyhow::{anyhow, Error};
3229
use reqwest::Client;
3330
use std::fs::File;
3431
use std::path::{Path, PathBuf};
@@ -241,6 +238,7 @@ pub fn record_desktop_with_ffmpeg(
241238
&recording_name,
242239
))
243240
};
244-
run_shell_command_with_log(log, os, command).unwrap();
245-
Ok(())
241+
run_shell_command_with_stderr(log, os, command, true).unwrap();
242+
243+
return Err(anyhow!("Command for recording desktop terminated")); // This line should be executed
246244
}

rust/src/shell.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,49 @@ pub fn run_shell_command_with_log(
6868
log: &Logger,
6969
os: &str,
7070
command: Command,
71+
) -> Result<String, Error> {
72+
run_shell_command_with_stderr(log, os, command, false)
73+
}
74+
75+
pub fn run_shell_command_with_stderr(
76+
log: &Logger,
77+
os: &str,
78+
command: Command,
79+
stderr: bool,
7180
) -> Result<String, Error> {
7281
log.debug(format!("Running command: {}", command.display()));
73-
let output = run_shell_command_by_os(os, command)?;
82+
let output = run_shell_command_by_os_stderr(os, command, stderr)?;
7483
log.debug(format!("Output: {:?}", output));
7584
Ok(output)
7685
}
7786

7887
pub fn run_shell_command_by_os(os: &str, command: Command) -> Result<String, Error> {
88+
run_shell_command_by_os_stderr(os, command, false)
89+
}
90+
91+
pub fn run_shell_command_by_os_stderr(
92+
os: &str,
93+
command: Command,
94+
stderr: bool,
95+
) -> Result<String, Error> {
7996
let (shell, flag) = if WINDOWS.is(os) {
8097
("cmd", "/c")
8198
} else {
8299
("sh", "-c")
83100
};
84-
run_shell_command(shell, flag, command)
101+
run_shell_command_stderr(shell, flag, command, stderr)
85102
}
86103

87104
pub fn run_shell_command(shell: &str, flag: &str, command: Command) -> Result<String, Error> {
105+
run_shell_command_stderr(shell, flag, command, false)
106+
}
107+
108+
pub fn run_shell_command_stderr(
109+
shell: &str,
110+
flag: &str,
111+
command: Command,
112+
stderr: bool,
113+
) -> Result<String, Error> {
88114
let mut process = std::process::Command::new(shell);
89115
process.arg(flag);
90116

@@ -96,9 +122,11 @@ pub fn run_shell_command(shell: &str, flag: &str, command: Command) -> Result<St
96122
}
97123
}
98124
let output = process.output()?;
99-
let stdout = String::from_utf8_lossy(&output.stdout);
100-
let stderr = String::from_utf8_lossy(&output.stderr);
101-
Ok(strip_trailing_newline(&(stdout + " " + stderr)).to_string())
125+
let mut stdout = String::from_utf8_lossy(&output.stdout);
126+
if stderr {
127+
stdout = stdout + " " + String::from_utf8_lossy(&output.stderr);
128+
}
129+
Ok(strip_trailing_newline(&stdout).to_string())
102130
}
103131

104132
pub fn strip_trailing_newline(input: &str) -> &str {

0 commit comments

Comments
 (0)