[英]Unable to use std::process::Command - No such file or directory
I am trying to use the following Rust code to connect to EC2 instances.我正在尝试使用以下 Rust 代码连接到 EC2 实例。
#[test]
fn client_ssh_timeout2() {
match Command::new("/usr/bin/ssh -i /tmp/.ssh/25.pem ubuntu@ip").spawn() {
Ok(_) => println!("Able to ssh"),
Err(e) => println!("{:?}", e),
};
}
But I am getting the following error但我收到以下错误
Error { repr: Os { code: 2, message: "No such file or directory" } }
Has anyone been able to use std::process::Command
or any other Rust library to connect to EC2 instances using PEM files?有没有人能够使用std::process::Command
或任何其他 Rust 库通过 PEM 文件连接到 EC2 实例? I tried using ssh2-rs(libssh2) but couldn't connect to EC2 instances.我尝试使用 ssh2-rs(libssh2) 但无法连接到 EC2 实例。
This appears to be a misunderstanding of how to use std::process:Command
.这似乎是对如何使用std::process:Command
的误解。 Command::new
takes just the program: Command::new
只需要程序:
fn new<S: AsRef<OsStr>>(program: S) -> Command
Command::arg
or Command::args
are used to provide the arguments. Command::arg
或Command::args
用于提供参数。
You will want something like你会想要类似的东西
Command::new("/usr/bin/ssh")
.args(&["-i", "/tmp/.ssh/25.pem", "ubuntu@ip"])
.spawn()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.