dwib
dwib

Reputation: 595

Rust - Can't run complex terminal Command

I'm trying to run a somewhat long command with rust:

rsync -avL --progress -e 'ssh -i ~/path/to/mypem.pem' ../directory/src/file.js user@computer:~/data/school

I tried to do it like this:

use std::process::Command;
let output = Command::new("rsync").args(&["-avL", "--progress", "-e", "'ssh", "-i", "~/path/to/mypem.pem'", "../directory/src/file.js", "user@computer:~/data/school"]).output().expect("BAD");

if !output.status.success() {
    let s = String::from_utf8_lossy(&output.stderr);
    print!("rustc failed and stderr was:\n{}", s);
}

println!("{}", String::from_utf8_lossy(&output.stdout));

This doesn't seem to work at all. It gives me this error:

Missing trailing-' in remote-shell command.

rsync error: syntax or usage error_

I'd really appreciate any help with what I'm doing wrong here. I've checked the docs for Command

Upvotes: 0

Views: 534

Answers (1)

harmic
harmic

Reputation: 30597

From the point of view of the rsync command, this bit:

ssh -i ~/path/to/mypem.pem

is one single argument, so you should not split it into multiple arguments.

Try this:

let output = Command::new("rsync").args(&["-avL", "--progress", "-e", "ssh -i ~/path/to/mypem.pem", "../directory/src/file.js", "user@computer:~/data/school"]).output().expect("BAD");

Upvotes: 4

Related Questions