1

I must execute rdiff-backup commands in Java. I desesperatly try to execute a backup command from local to remote with Runtime.

I need to use a remote schema because I can't connect to standart port 22.

As same commands work in windows shell, remote commands refuse to work, I've tried something like this :

Runtime r = Runtime.getRuntime();
Process proc = r.exec("C:/rdiff/rdiff-backup.exe "
+"--remote-schema="
+"ssh -C -p16000 %s rdiff-backup --server "
+"C:/Users/Utilisateur/Desktop/backup "
+"user@xxx.net::/var/backup");

getting this error : Fatal Error: Bad commandline options: option -C not recognized

or

String[] commandLine= {"C:/rdiff/rdiff-backup.exe",
"C:/Users/Utilisateur/Desktop/backup",
"\"-p 16000 user@xxx.net\"",
"::/var/backups"};

Runtime r = Runtime.getRuntime();
Process proc = r.exec(commandLine);

getting this error : Fatal Error: Switches missing or wrong number of arguments

Thanks for your help...

Greg B
  • 13
  • 5

1 Answers1

0

The first method you use is ok in java. But your command line is wrong - ssh -C is not a proper command. Make sure the command works in your shell, then use it in your first method.

Christian Cerri
  • 1,233
  • 2
  • 15
  • 19
  • Thank you very much ! It finally works with : Process proc = r.exec("C:/rdiff/rdiff-backup.exe " +"--remote-schema " +"\"ssh -p16000 %s rdiff-backup --server\" " +"C:/Users/Utilisateur/Desktop/backup " +"user@xxx.net::/var/backups"); But I don't get the answer (hopefully 0) with InputStream is = proc.getInputStream(); result = new BufferedReader(new InputStreamReader(is)).lines().collect(Collectors.joining("\n")); – Greg B May 10 '16 at 06:29
  • see http://stackoverflow.com/questions/5711084/java-runtime-getruntime-getting-output-from-executing-a-command-line-program for a solution on reading output from the command – Christian Cerri May 10 '16 at 07:18