Files
tauri/tauri-api/src/command.rs
Tensor-Programming e288180104 [WIP] Refactor(Crates) Tauri into individual Crates (#192)
* split tauri into 3 crates

* fix macros

* change builder into lib

* cleanup package paths

* add features back to lib

* make build function public

* add build-deps

* rename and fix.

* correct package name

* move crates to root and refactor names

* fix github action

* move fixture to tauri-build

* remove slash

* add .vscode features

* fix updater

* fix updater mistake

* fix(tauri) refactor buiilds

* fix seperation

* change get back to get

* fix cfg and remove dead code warnings.

* roll #160 into this pr

* add credit

* fix eof

* chore(tauri) move assets to mod, loadAssets cfg outside its definition

* chore(tauri) remove unused deps

* update updater and cfg

* fix(tauri) embedded-server with dead variable

* add review refactors and remove cli form workgroup

* chore(tauri) rename tauri to tauri-api and tauri-bundle to tauri

* fix workspace and updater

* rename update to updater
2019-12-22 14:04:45 -05:00

56 lines
1.6 KiB
Rust

use std::process::{Child, Command, Stdio};
pub fn get_output(cmd: String, args: Vec<String>, stdout: Stdio) -> Result<String, String> {
Command::new(cmd)
.args(args)
.stdout(stdout)
.output()
.map_err(|err| err.to_string())
.and_then(|output| {
if output.status.success() {
return Result::Ok(String::from_utf8_lossy(&output.stdout).to_string());
} else {
return Result::Err(String::from_utf8_lossy(&output.stderr).to_string());
}
})
}
// TODO use .exe for windows builds
pub fn format_command(path: String, command: String) -> String {
return format!("{}/./{}", path, command);
}
pub fn relative_command(command: String) -> Result<String, std::io::Error> {
match std::env::current_exe()?.parent() {
Some(exe_dir) => return Ok(format_command(exe_dir.display().to_string(), command)),
None => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Could not evaluate executable dir".to_string(),
))
}
}
}
// TODO append .exe for windows builds
pub fn command_path(command: String) -> Result<String, std::io::Error> {
match std::env::current_exe()?.parent() {
Some(exe_dir) => return Ok(format!("{}/{}", exe_dir.display().to_string(), command)),
None => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Could not evaluate executable dir".to_string(),
))
}
}
}
pub fn spawn_relative_command(
command: String,
args: Vec<String>,
stdout: Stdio,
) -> Result<Child, std::io::Error> {
let cmd = relative_command(command)?;
Ok(Command::new(cmd).args(args).stdout(stdout).spawn()?)
}