Don't build the command line yourself, let Exec do it: http://commons.apache.org/proper/commons-exec/commandline.html#Building_the_Command_Line_Incrementally
On 26 August 2015 at 03:34, Tech Dev <[email protected]> wrote: > Hi, > > I am trying to execute a copy command using Apache Commons Exec API. Below > is my effort : > > String initialCommand = "scp -i"; > String privateKey = "/Users/TD/.ssh/id_rsa"; > String currentFile = "/Users/TD/One.txt"; > String target = "[email protected]:"; > > // Space is present in destination > String destination="/Leo/Ta/San Diego"; > destination=destination.replaceAll(" ", "\\\\ "); > > String completeCommand = initialCommand + " " + privateKey + " " + > currentFile + " " + target + destination; > System.out.println(completeCommand); > > CommandLine commandLine = new CommandLine(completeCommand); > > System.out.println(commandLine.toString()); > DefaultExecutor executor = new DefaultExecutor(); > executor.setExitValue(0); > executor.execute(commandLine); > > Output : > >> scp -i /Users/TD/.ssh/id_rsa /Users/TD/One.txt >> [email protected]:/Leo/Ta/San\ > Diego > >> scp -i /Users/TD/.ssh/id_rsa /Users/TD/One.txt >> [email protected]:/Leo/Ta/San/ > Diego > > I am noticing that backslash is getting updated and also my command is not > running with error "No such file or directory". > > I am new to this library. Any suggestion would be appreciated. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
