pub struct Command { /* private fields */ }
Implementations§
source§impl Command
impl Command
sourcepub fn new(name: &str) -> Self
pub fn new(name: &str) -> Self
Examples found in repository?
examples/command.rs (line 9)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
fn main() -> Result<()> {
let c2 = Command::new("git")
.arg("log")
.arg("-1")
.current_dir(&std::env::current_dir().unwrap())
.exec()?;
println!("command display: {}", c2);
println!("\ncommand debug:\n{:#?}", c2);
println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);
let c3 = Command::new("git")
.arg("ls-remote")
.arg("https://gitlab.com/crates-rs/reef.git")
.arg("HEAD")
.timeout(Duration::new(0, 0))
.exec()?;
println!("{:#?}", c3);
let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
println!("{:#?}", c4);
let rake_dir = std::env::temp_dir().join("reef.command.rake");
if !rake_dir.exists() {
std::fs::create_dir_all(&rake_dir)?;
}
let rakefile = rake_dir.join("rakefile.rb");
let mut file = File::create(&rakefile)?;
file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
file.flush()?;
thread::sleep(Duration::from_millis(500));
let rake = Command::new("rake")
.arg("default")
.current_dir(&rake_dir)
.timeout(std::time::Duration::from_secs(20 * 60))
.exec()?;
println!("{:#?}", rake);
std::fs::remove_file(&rakefile)?;
std::fs::remove_dir_all(&rake_dir)?;
// collect recent history
let recent = Command::collect("", 3)?;
println!("recent:\n{:#?}", recent);
Ok(())
}
sourcepub fn collect(search: &str, limit: usize) -> Result<Vec<Command>>
pub fn collect(search: &str, limit: usize) -> Result<Vec<Command>>
Examples found in repository?
examples/command.rs (line 48)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
fn main() -> Result<()> {
let c2 = Command::new("git")
.arg("log")
.arg("-1")
.current_dir(&std::env::current_dir().unwrap())
.exec()?;
println!("command display: {}", c2);
println!("\ncommand debug:\n{:#?}", c2);
println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);
let c3 = Command::new("git")
.arg("ls-remote")
.arg("https://gitlab.com/crates-rs/reef.git")
.arg("HEAD")
.timeout(Duration::new(0, 0))
.exec()?;
println!("{:#?}", c3);
let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
println!("{:#?}", c4);
let rake_dir = std::env::temp_dir().join("reef.command.rake");
if !rake_dir.exists() {
std::fs::create_dir_all(&rake_dir)?;
}
let rakefile = rake_dir.join("rakefile.rb");
let mut file = File::create(&rakefile)?;
file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
file.flush()?;
thread::sleep(Duration::from_millis(500));
let rake = Command::new("rake")
.arg("default")
.current_dir(&rake_dir)
.timeout(std::time::Duration::from_secs(20 * 60))
.exec()?;
println!("{:#?}", rake);
std::fs::remove_file(&rakefile)?;
std::fs::remove_dir_all(&rake_dir)?;
// collect recent history
let recent = Command::collect("", 3)?;
println!("recent:\n{:#?}", recent);
Ok(())
}
source§impl Command
impl Command
pub fn name(&self) -> &str
pub fn args(&self) -> &Vec<String>
pub fn exe_filename(&self) -> &Path
pub fn working_directory(&self) -> Option<&Path>
pub fn get_timeout(&self) -> Option<&Duration>
pub fn stderr(&self) -> &Vec<u8>
pub fn timed_out(&self) -> bool
pub fn exit_code(&self) -> Option<i32>
pub fn start(&self) -> &Option<DateTime<Utc>>
pub fn duration(&self) -> Option<Duration>
pub fn duration_string(&self) -> String
pub fn stdout(&self) -> &Vec<u8>
pub fn text(&self) -> Result<String>
pub fn status(&self) -> Status
pub fn user(&self) -> &str
pub fn machine(&self) -> &str
pub fn os(&self) -> &str
pub fn matches(&self, search: &str) -> bool
source§impl Command
impl Command
sourcepub fn arg(&mut self, arg: &str) -> &mut Command
pub fn arg(&mut self, arg: &str) -> &mut Command
Examples found in repository?
examples/command.rs (line 10)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
fn main() -> Result<()> {
let c2 = Command::new("git")
.arg("log")
.arg("-1")
.current_dir(&std::env::current_dir().unwrap())
.exec()?;
println!("command display: {}", c2);
println!("\ncommand debug:\n{:#?}", c2);
println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);
let c3 = Command::new("git")
.arg("ls-remote")
.arg("https://gitlab.com/crates-rs/reef.git")
.arg("HEAD")
.timeout(Duration::new(0, 0))
.exec()?;
println!("{:#?}", c3);
let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
println!("{:#?}", c4);
let rake_dir = std::env::temp_dir().join("reef.command.rake");
if !rake_dir.exists() {
std::fs::create_dir_all(&rake_dir)?;
}
let rakefile = rake_dir.join("rakefile.rb");
let mut file = File::create(&rakefile)?;
file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
file.flush()?;
thread::sleep(Duration::from_millis(500));
let rake = Command::new("rake")
.arg("default")
.current_dir(&rake_dir)
.timeout(std::time::Duration::from_secs(20 * 60))
.exec()?;
println!("{:#?}", rake);
std::fs::remove_file(&rakefile)?;
std::fs::remove_dir_all(&rake_dir)?;
// collect recent history
let recent = Command::collect("", 3)?;
println!("recent:\n{:#?}", recent);
Ok(())
}
sourcepub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Command
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Command
Examples found in repository?
examples/command.rs (line 12)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
fn main() -> Result<()> {
let c2 = Command::new("git")
.arg("log")
.arg("-1")
.current_dir(&std::env::current_dir().unwrap())
.exec()?;
println!("command display: {}", c2);
println!("\ncommand debug:\n{:#?}", c2);
println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);
let c3 = Command::new("git")
.arg("ls-remote")
.arg("https://gitlab.com/crates-rs/reef.git")
.arg("HEAD")
.timeout(Duration::new(0, 0))
.exec()?;
println!("{:#?}", c3);
let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
println!("{:#?}", c4);
let rake_dir = std::env::temp_dir().join("reef.command.rake");
if !rake_dir.exists() {
std::fs::create_dir_all(&rake_dir)?;
}
let rakefile = rake_dir.join("rakefile.rb");
let mut file = File::create(&rakefile)?;
file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
file.flush()?;
thread::sleep(Duration::from_millis(500));
let rake = Command::new("rake")
.arg("default")
.current_dir(&rake_dir)
.timeout(std::time::Duration::from_secs(20 * 60))
.exec()?;
println!("{:#?}", rake);
std::fs::remove_file(&rakefile)?;
std::fs::remove_dir_all(&rake_dir)?;
// collect recent history
let recent = Command::collect("", 3)?;
println!("recent:\n{:#?}", recent);
Ok(())
}
sourcepub fn timeout(&mut self, timeout: Duration) -> &mut Command
pub fn timeout(&mut self, timeout: Duration) -> &mut Command
Examples found in repository?
examples/command.rs (line 22)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
fn main() -> Result<()> {
let c2 = Command::new("git")
.arg("log")
.arg("-1")
.current_dir(&std::env::current_dir().unwrap())
.exec()?;
println!("command display: {}", c2);
println!("\ncommand debug:\n{:#?}", c2);
println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);
let c3 = Command::new("git")
.arg("ls-remote")
.arg("https://gitlab.com/crates-rs/reef.git")
.arg("HEAD")
.timeout(Duration::new(0, 0))
.exec()?;
println!("{:#?}", c3);
let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
println!("{:#?}", c4);
let rake_dir = std::env::temp_dir().join("reef.command.rake");
if !rake_dir.exists() {
std::fs::create_dir_all(&rake_dir)?;
}
let rakefile = rake_dir.join("rakefile.rb");
let mut file = File::create(&rakefile)?;
file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
file.flush()?;
thread::sleep(Duration::from_millis(500));
let rake = Command::new("rake")
.arg("default")
.current_dir(&rake_dir)
.timeout(std::time::Duration::from_secs(20 * 60))
.exec()?;
println!("{:#?}", rake);
std::fs::remove_file(&rakefile)?;
std::fs::remove_dir_all(&rake_dir)?;
// collect recent history
let recent = Command::collect("", 3)?;
println!("recent:\n{:#?}", recent);
Ok(())
}
pub fn success_log_level(&mut self, level_filter: LevelFilter) -> &mut Command
pub fn fail_log_level(&mut self, level_filter: LevelFilter) -> &mut Command
sourcepub fn exec(&mut self) -> Result<Command>
pub fn exec(&mut self) -> Result<Command>
Examples found in repository?
examples/command.rs (line 13)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
fn main() -> Result<()> {
let c2 = Command::new("git")
.arg("log")
.arg("-1")
.current_dir(&std::env::current_dir().unwrap())
.exec()?;
println!("command display: {}", c2);
println!("\ncommand debug:\n{:#?}", c2);
println!("\ncommand json compact: {}", serde_json::to_string(&c2)?);
let c3 = Command::new("git")
.arg("ls-remote")
.arg("https://gitlab.com/crates-rs/reef.git")
.arg("HEAD")
.timeout(Duration::new(0, 0))
.exec()?;
println!("{:#?}", c3);
let c4 = Command::new("git ls-remote https://gitlab.com/crates-rs/reef.git HEAD").exec()?;
println!("{:#?}", c4);
let rake_dir = std::env::temp_dir().join("reef.command.rake");
if !rake_dir.exists() {
std::fs::create_dir_all(&rake_dir)?;
}
let rakefile = rake_dir.join("rakefile.rb");
let mut file = File::create(&rakefile)?;
file.write_all(b"task :default do\nputs 'Hello'\n$stderr.puts 'stderr'\nraise 'failure'\nend")?;
file.flush()?;
thread::sleep(Duration::from_millis(500));
let rake = Command::new("rake")
.arg("default")
.current_dir(&rake_dir)
.timeout(std::time::Duration::from_secs(20 * 60))
.exec()?;
println!("{:#?}", rake);
std::fs::remove_file(&rakefile)?;
std::fs::remove_dir_all(&rake_dir)?;
// collect recent history
let recent = Command::collect("", 3)?;
println!("recent:\n{:#?}", recent);
Ok(())
}
pub fn set_stdout(&mut self, stdout: Vec<u8>)
pub fn set_stderr(&mut self, stderr: Vec<u8>)
Trait Implementations§
source§impl<'de> Deserialize<'de> for Command
impl<'de> Deserialize<'de> for Command
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl RefUnwindSafe for Command
impl Send for Command
impl Sync for Command
impl Unpin for Command
impl UnwindSafe for Command
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more