2

On a linux box I am making the following SVN import command:

svn import
           --non-interactive 
           --trust-server-cert 
           --username username 
           --password password 
           -m "a message" 
           /path/to/local.zip 
           https://sub.domain.net/path/to/export.zip

When calling it from the command line myself it works without a problem.

However, if I make this call using a a Java command prompt then I receieve an error message that there are too many arguments in the import command.

Does anyone know what could be causing this?

Additional notes

  • If I copy and paste the Java generated svn import command from my log file to the console then the import works as expected.

  • I am able to use SVN export command from within Java without any problems

  • I have tried using single ' quotes

Edit

The code to make these calls are as follows:

private void exportToSvn()
    String command = String.format(
            "svn import --non-interactive --trust-server-cert " +
            "--username %s --password %s -m %s %s %s",
            username, password, "\"a message\"", "/path/to/local.zip",
            "https://sub.domain.net/path/to/export.zip"
    );
    command( command );
}

private void command( String... commands ) throws IOException, InterruptedException {
    Runtime rt = Runtime.getRuntime();
    for( String command : commands ){
        Process pr = rt.exec( command );
        BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
        logger.debug( command );
        String line;
        while ( (line = input.readLine()) != null)
            logger.debug("> " + line);
    }
My Head Hurts
  • 37,315
  • 16
  • 75
  • 117
  • What subversion library and version are you using on the command line vs. in Java? Are you using a library that uses the native svn or a pure Java library like SVNKit? You should try swapping in another SVN connection library and see if it exhibits the same issue. – Ray May 07 '12 at 13:07
  • What's with the extra `svn` at the end of `svn import svn`? When copied to the CLI, that _works_ as you say in your post? – Michael Berkowski May 07 '12 at 13:12
  • @Ray the sub version library is the same for both the command line and Java and is just using the native version. – My Head Hurts May 07 '12 at 13:12
  • @Michael - thanks, it was a typo and has been corrected now. You didn't just happen to link to [this question](http://stackoverflow.com/q/3190190/681807) in a previous (now deleted) comment did you? – My Head Hurts May 07 '12 at 13:14
  • @Michael ok, no problem. Someone did and I didn't catch their name before they deleted it. I think it might have something to do with my problem as I am sure the issue is with the quotes. – My Head Hurts May 07 '12 at 13:17
  • 1
    How are you calling the svn command? ProcessBuilder? It will help if you could copy the code you are using. – Daniel H. May 07 '12 at 13:27
  • @DanielH. I have added the code to the question – My Head Hurts May 07 '12 at 14:00

3 Answers3

1

I suggest you to use the recommended ProcessBuilder instead of Process. It gives you more control on the execution, and it permits to specify the list of arguments. It may solve your problem and it only requires minor modifications in the code.

Daniel H.
  • 1,782
  • 16
  • 18
  • +1 thanks for the answer. The problem was actually with the inability to escape the double quotes which I believe would occur with process builder as well. I will try using process Builder in future and see what advantages it brings. – My Head Hurts May 07 '12 at 14:18
1

After an anonymous tip (the commenter deleted their comment before I caught their name) - I found that the problem lay with the quotes as they cannot be escaped within Process (see this question).

String message = "\"Some message\"";    //quotes aren't escaped

I found a work around for this was to include the quotes in char format instead:

String message = String.format( "%sSome message%s", (char)34 );  //quotes as char
Community
  • 1
  • 1
My Head Hurts
  • 37,315
  • 16
  • 75
  • 117
0

Try this to Commit file using Terminal

If you have any spaces in folder name, just use a backword slash just before the space

for example:

svn import -m "Here i'm gonna commit" /Users/Ram/Documents/Ram\ file1/ http://svnlocation/svnFolder\ 2654/

Here my file name is: Ram file1

SVN folder name is: svnFolder 2654

Please make sure that there are no extra spaces coming after during copying.

Ram Madhavan
  • 2,362
  • 1
  • 17
  • 20