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 <techdev...@gmail.com> 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 = "r...@my.server.com:";
>
>         // 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 
>> r...@my.server.com:/Leo/Ta/San\
> Diego
>
>> scp -i /Users/TD/.ssh/id_rsa /Users/TD/One.txt 
>> r...@my.server.com:/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: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org

Reply via email to