fix(windows): use cmd on windows instead of sh (#102)

Co-authored-by: liyixin <root@liyixin-test.sci-inv.cn>
This commit is contained in:
liyixin 2024-12-06 17:37:44 +08:00 committed by GitHub
parent 4567f26a37
commit f9d33e4797
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 4 deletions

View File

@ -5,6 +5,7 @@ use television_fuzzy::{
matcher::{config::Config, injector::Injector}, matcher::{config::Config, injector::Injector},
Matcher, Matcher,
}; };
use television_utils::command::shell_command;
#[allow(dead_code)] #[allow(dead_code)]
pub struct Channel { pub struct Channel {
@ -57,8 +58,7 @@ impl Channel {
#[allow(clippy::unused_async)] #[allow(clippy::unused_async)]
async fn load_candidates(command: String, injector: Injector<String>) { async fn load_candidates(command: String, injector: Injector<String>) {
let output = std::process::Command::new("sh") let output = shell_command()
.arg("-c")
.arg(command) .arg(command)
.output() .output()
.expect("failed to execute process"); .expect("failed to execute process");

View File

@ -8,6 +8,7 @@ use std::collections::HashSet;
use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::atomic::{AtomicU8, Ordering};
use std::sync::Arc; use std::sync::Arc;
use television_channels::entry::{Entry, PreviewCommand}; use television_channels::entry::{Entry, PreviewCommand};
use television_utils::command::shell_command;
use tracing::debug; use tracing::debug;
#[allow(dead_code)] #[allow(dead_code)]
@ -151,8 +152,7 @@ pub fn try_preview(
let command = format_command(command, entry); let command = format_command(command, entry);
debug!("Formatted preview command: {:?}", command); debug!("Formatted preview command: {:?}", command);
let output = std::process::Command::new("sh") let output = shell_command()
.arg("-c")
.arg(&command) .arg(&command)
.output() .output()
.expect("failed to execute process"); .expect("failed to execute process");

View File

@ -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
}

View File

@ -1,4 +1,5 @@
pub mod cache; pub mod cache;
pub mod command;
pub mod files; pub mod files;
pub mod indices; pub mod indices;
pub mod stdin; pub mod stdin;