first try.
This commit is contained in:
parent
bdc42bfa90
commit
2c14b698bc
@ -1,5 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GitSharedSettings">
|
||||||
|
<option name="FORCE_PUSH_PROHIBITED_PATTERNS">
|
||||||
|
<list />
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
|
50
src/main.rs
50
src/main.rs
@ -1,3 +1,49 @@
|
|||||||
fn main() {
|
use std::env;
|
||||||
println!("Hello, world!");
|
use std::io::{self, Write};
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
fn retry(cmd: &String, cmd_args: &[String]) {
|
||||||
|
loop {
|
||||||
|
let output = Command::new(cmd)
|
||||||
|
.args(cmd_args)
|
||||||
|
.output()
|
||||||
|
.map_err(|e| {
|
||||||
|
eprintln!("Failed to execute command: {}", e);
|
||||||
|
io::stderr().flush().unwrap();
|
||||||
|
});
|
||||||
|
|
||||||
|
match output {
|
||||||
|
Ok(output) => {
|
||||||
|
if output.status.success() {
|
||||||
|
io::stdout().write_all(&output.stdout).unwrap();
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
eprintln!("Command failed with status: {}", output.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
println!("Error, wait 1s for retry.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
|
if args.len() < 2 {
|
||||||
|
eprintln!("Usage: {} <cmd> [args...]", args[0]);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let cmd = &args[1];
|
||||||
|
let cmd_args = if args.len() > 2 {
|
||||||
|
&args[2..]
|
||||||
|
} else {
|
||||||
|
&[]
|
||||||
|
};
|
||||||
|
|
||||||
|
retry(cmd, cmd_args);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user