commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: [exec] - Simple Copy using Apache Commons
Date Wed, 26 Aug 2015 21:53:53 GMT
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 <techdevsmu@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 = "root@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 root@my.server.com:/Leo/Ta/San\
> Diego
>
>> scp -i /Users/TD/.ssh/id_rsa /Users/TD/One.txt root@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-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message