From f9d33e4797e6d21bf27de62d51ecd8985455a5a2 Mon Sep 17 00:00:00 2001 From: liyixin <601947961@qq.com> Date: Fri, 6 Dec 2024 17:37:44 +0800 Subject: [PATCH] fix(windows): use cmd on windows instead of sh (#102) Co-authored-by: liyixin --- .../television-channels/src/channels/cable.rs | 4 ++-- .../src/previewers/command.rs | 4 ++-- crates/television-utils/src/command.rs | 19 +++++++++++++++++++ crates/television-utils/src/lib.rs | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 crates/television-utils/src/command.rs diff --git a/crates/television-channels/src/channels/cable.rs b/crates/television-channels/src/channels/cable.rs index 11a0866..0fa8d58 100644 --- a/crates/television-channels/src/channels/cable.rs +++ b/crates/television-channels/src/channels/cable.rs @@ -5,6 +5,7 @@ use television_fuzzy::{ matcher::{config::Config, injector::Injector}, Matcher, }; +use television_utils::command::shell_command; #[allow(dead_code)] pub struct Channel { @@ -57,8 +58,7 @@ impl Channel { #[allow(clippy::unused_async)] async fn load_candidates(command: String, injector: Injector) { - let output = std::process::Command::new("sh") - .arg("-c") + let output = shell_command() .arg(command) .output() .expect("failed to execute process"); diff --git a/crates/television-previewers/src/previewers/command.rs b/crates/television-previewers/src/previewers/command.rs index 487924b..827e077 100644 --- a/crates/television-previewers/src/previewers/command.rs +++ b/crates/television-previewers/src/previewers/command.rs @@ -8,6 +8,7 @@ use std::collections::HashSet; use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::Arc; use television_channels::entry::{Entry, PreviewCommand}; +use television_utils::command::shell_command; use tracing::debug; #[allow(dead_code)] @@ -151,8 +152,7 @@ pub fn try_preview( let command = format_command(command, entry); debug!("Formatted preview command: {:?}", command); - let output = std::process::Command::new("sh") - .arg("-c") + let output = shell_command() .arg(&command) .output() .expect("failed to execute process"); diff --git a/crates/television-utils/src/command.rs b/crates/television-utils/src/command.rs new file mode 100644 index 0000000..2926bb5 --- /dev/null +++ b/crates/television-utils/src/command.rs @@ -0,0 +1,19 @@ +use std::process::Command; + +#[cfg(not(windows))] +pub fn shell_command() -> Command { + let mut cmd = Command::new("sh"); + + cmd.arg("-c"); + + cmd +} + +#[cfg(windows)] +pub fn shell_command() -> Command { + let mut cmd = Command::new("cmd"); + + cmd.arg("/c"); + + cmd +} diff --git a/crates/television-utils/src/lib.rs b/crates/television-utils/src/lib.rs index 5c4bb12..c11c104 100644 --- a/crates/television-utils/src/lib.rs +++ b/crates/television-utils/src/lib.rs @@ -1,4 +1,5 @@ pub mod cache; +pub mod command; pub mod files; pub mod indices; pub mod stdin;