use std::fs;
use std::process::Command;
use std::env;
use std::string;
use regex::{Captures, Regex};
fn main(){
println!("命令手册: deploy /home/xxx/ware/exec /home/xxx/ware/save_lib");
let args: Vec<String>= env::args().collect();if args.len()!=3{
println!("格式错误");return;}
let exe_path =&args[1];
let dest_path =&args[2];
let re =egex::new(r">.+\(").expect("匹配失败");
println!("exe_path is {:?}",exe_path);
println!("lib_save_dest_path is {:?}",dest_path);
let output =Command::new("ldd").arg(exe_path).output().unwrap();
let libs_path =String::from_utf8(output.stdout).unwrap();
let libs_path_trim = libs_path.trim();
let libs_path_vec:Vec<&str>= libs_path_trim.split("\n\t").collect();//println!("{:?}",libs_path_vec);
println!("依赖库位置如下:");for libs in libs_path_vec{
match re.captures(libs){
None =>{}Some(lib)=>{
let lib_path_width_errors =&lib[0].to_owned();
let lib_path = lib_path_width_errors[1..lib_path_width_errors.len()-1].trim();
let lib_name = lib_path.split('/').last().unwrap();
println!("{:?}",lib_name);
fs::copy(lib_path, format!("{}/{}", dest_path, lib_name)).expect("复制失败");}};}}